Post delete, Profile edit
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
import { TFunction } from 'i18next';
|
||||
|
||||
export enum ERRORS {
|
||||
NOT_FOUND = 'NotFound',
|
||||
UNAUTHORIZED = 'Unauthorized',
|
||||
}
|
||||
|
||||
/**
|
||||
* Return translated error
|
||||
* @param error Error object
|
||||
* @param context Optional context
|
||||
* @param t Optional translation function, defautls to pass through
|
||||
* @returns Translated error or inputs if t as unspecified
|
||||
*/
|
||||
const handleError = (
|
||||
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
error: any,
|
||||
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
t: TFunction<'translation', undefined> | ((..._in: any) => any) = (..._in: any) => _in,
|
||||
context?: string
|
||||
): string => {
|
||||
console.log(context);
|
||||
if (!error) return t('', {});
|
||||
|
||||
if (error.code) {
|
||||
switch (error.code) {
|
||||
case ERRORS.NOT_FOUND:
|
||||
return t(error.code, { context: `${error.entity}:${context}` });
|
||||
case ERRORS.UNAUTHORIZED:
|
||||
return t(error.code, { context });
|
||||
default:
|
||||
return t('Unknown', { context });
|
||||
}
|
||||
}
|
||||
|
||||
return t(error?.message ?? 'Unknown', { context });
|
||||
};
|
||||
|
||||
export default handleError;
|
||||
Reference in New Issue
Block a user