Post delete, Profile edit

This commit is contained in:
2024-07-27 00:54:23 +02:00
parent a515c447e0
commit 581cacb636
33 changed files with 533 additions and 238 deletions
-39
View File
@@ -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;