mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
fixed error translation
This commit is contained in:
parent
455c7ad90d
commit
a7d890aeec
5 changed files with 46 additions and 11 deletions
17
src/utils/hooks/useTranslatedError.ts
Normal file
17
src/utils/hooks/useTranslatedError.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { ERROR_LITERAL } from '~/constants/errors';
|
||||
import { has } from 'ramda';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
export const useTranslatedError = (error: string | undefined) => {
|
||||
return useMemo(() => {
|
||||
if (!error) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!has(error, ERROR_LITERAL)) {
|
||||
return error;
|
||||
}
|
||||
|
||||
return ERROR_LITERAL[error];
|
||||
}, [error]);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue