mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-26 05:16:41 +07:00
removed player reducer, migrated to CRA 5
This commit is contained in:
parent
88f8fe21f7
commit
558e8f8a4f
211 changed files with 7131 additions and 10318 deletions
25
src/utils/errors/getErrorMessage.ts
Normal file
25
src/utils/errors/getErrorMessage.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { has, path } from 'ramda';
|
||||
import { ERROR_LITERAL, ERRORS } from '~/constants/errors';
|
||||
|
||||
export const getErrorMessage = (error: unknown) => {
|
||||
if (typeof error === 'string' && has(error, ERROR_LITERAL)) {
|
||||
return ERROR_LITERAL[error];
|
||||
}
|
||||
|
||||
if (!(error instanceof Error)) {
|
||||
console.warn('catched strange exception', error);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Network error
|
||||
if (error.message === 'Network Error') {
|
||||
return ERROR_LITERAL[ERRORS.NETWORK_ERROR];
|
||||
}
|
||||
|
||||
const messageFromBackend = String(path(['response', 'data', 'error'], error));
|
||||
if (messageFromBackend && has(messageFromBackend, ERROR_LITERAL)) {
|
||||
return ERROR_LITERAL[messageFromBackend];
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
9
src/utils/errors/getValidationErrors.ts
Normal file
9
src/utils/errors/getValidationErrors.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { hasPath, path } from 'ramda';
|
||||
|
||||
export const getValidationErrors = (error: unknown): Record<string, string> | undefined => {
|
||||
if (hasPath(['response', 'data', 'errors'], error)) {
|
||||
return path(['response', 'data', 'errors'], error);
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
|
@ -1,6 +1,5 @@
|
|||
import { hideToast, showToastError } from '~/utils/toast';
|
||||
import { has, path } from 'ramda';
|
||||
import { ERROR_LITERAL, ERRORS } from '~/constants/errors';
|
||||
import { getErrorMessage } from '~/utils/errors/getErrorMessage';
|
||||
|
||||
let toastId = '';
|
||||
|
||||
|
@ -10,29 +9,16 @@ const handleTranslated = (message: string) => {
|
|||
hideToast(toastId);
|
||||
}
|
||||
|
||||
toastId = showToastError(ERROR_LITERAL[message]);
|
||||
toastId = showToastError(message);
|
||||
};
|
||||
|
||||
export const showErrorToast = (error: unknown) => {
|
||||
if (typeof error === 'string' && has(error, ERROR_LITERAL)) {
|
||||
handleTranslated(error);
|
||||
return;
|
||||
const message = getErrorMessage(error);
|
||||
if (message) {
|
||||
return handleTranslated(message);
|
||||
}
|
||||
|
||||
if (!(error instanceof Error)) {
|
||||
console.warn('catched strange exception', error);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Network error
|
||||
if (error.message === 'Network Error') {
|
||||
handleTranslated(ERRORS.NETWORK_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
const messageFromBackend = String(path(['response', 'data', 'error'], error));
|
||||
if (messageFromBackend && has(messageFromBackend, ERROR_LITERAL)) {
|
||||
handleTranslated(messageFromBackend);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue