mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00

* fixed paths to match refactored backend * fixed some paths according to new backend * fixed auth urls for new endpoints * fixed urls * fixed error handling * fixes * fixed error handling on user form * fixed error handling on oauth * using fallback: true on node pages * type button for comment attach buttons * fixed return types of social delete * changed the way we upload user avatars
33 lines
913 B
TypeScript
33 lines
913 B
TypeScript
import { ERROR_LITERAL, ERRORS } from '~/constants/errors';
|
|
import { has, path } from '~/utils/ramda';
|
|
|
|
export const getErrorMessage = (error: unknown): string | undefined => {
|
|
if (error === undefined) {
|
|
return undefined;
|
|
}
|
|
|
|
if (path(['response', 'data', 'message'], error)) {
|
|
return path(['response', 'data', 'message'], error) as string;
|
|
}
|
|
|
|
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;
|
|
};
|