mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-26 05:16:41 +07:00
added toasts
This commit is contained in:
parent
ef959af711
commit
39e801f6f3
10 changed files with 92 additions and 7 deletions
|
@ -1,8 +1,21 @@
|
|||
const handle = (message: string) => console.warn(message);
|
||||
import { hideToast, showToastError } from '~/utils/toast';
|
||||
import { has, path } from 'ramda';
|
||||
import { ERROR_LITERAL, ERRORS } from '~/constants/errors';
|
||||
|
||||
let toastId = '';
|
||||
|
||||
const handleUnknown = (message: string) => console.warn(message);
|
||||
const handleTranslated = (message: string) => {
|
||||
if (toastId) {
|
||||
hideToast(toastId);
|
||||
}
|
||||
|
||||
toastId = showToastError(ERROR_LITERAL[message]);
|
||||
};
|
||||
|
||||
export const showErrorToast = (error: unknown) => {
|
||||
if (typeof error === 'string') {
|
||||
handle(error);
|
||||
if (typeof error === 'string' && has(error, ERROR_LITERAL)) {
|
||||
handleTranslated(error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -11,5 +24,17 @@ export const showErrorToast = (error: unknown) => {
|
|||
return;
|
||||
}
|
||||
|
||||
handle(error.message);
|
||||
// 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;
|
||||
}
|
||||
|
||||
handleUnknown(error.message);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue