Login/Logout + Menu + i18next

This commit is contained in:
2024-07-25 01:09:20 +02:00
parent dd48f72c42
commit 65848f094b
17 changed files with 1042 additions and 211 deletions
+25
View File
@@ -0,0 +1,25 @@
/**
* Transform error into i18next spreadable input
* @param error Error object
* @param context Optional context for translation
* @returns Array to be spread into i18next `t` function
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleError = (error: any, context?: string): [string, { context?: string }] => {
if (!error) return ['', {}];
if (error.code) {
switch (error.code) {
case 'NotFound':
return [error.code, { context: `${error.entity}:${context}` }];
case 'Unauthorized':
return [error.code, { context }];
default:
return ['Unknown', { context }];
}
}
return [error?.message ?? 'Unknown', { context }];
};
export default handleError;