Login/Logout + Menu + i18next
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user