Include actual error in snackbar

This commit is contained in:
schroda
2024-12-20 17:24:40 +01:00
parent 91a1f75de6
commit 3949363474
44 changed files with 292 additions and 91 deletions

View File

@@ -6,6 +6,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { ApolloError } from '@apollo/client/errors';
export const jsonSaveParse = <T = any>(...args: Parameters<typeof JSON.parse>): T | null => {
try {
return JSON.parse(...args);
@@ -13,3 +15,19 @@ export const jsonSaveParse = <T = any>(...args: Parameters<typeof JSON.parse>):
return null;
}
};
export const getErrorMessage = (error: unknown): string => {
if (error instanceof ApolloError) {
return `${error.name}: ${error.message}`;
}
if (error instanceof Error) {
return `${error.name}: ${error.message}`;
}
if (error == null) {
return '';
}
return `${error}`;
};