Skip to content

Commit

Permalink
frontend: better toast errors
Browse files Browse the repository at this point in the history
  • Loading branch information
allgood committed Sep 9, 2024
1 parent e415f98 commit cfab86e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion frontend/src/errors/toastError.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { i18n } from "../translate/i18n";
import { isString } from 'lodash';

const toastError = err => {
const errorMsg = err.response?.data?.error;
const errorMsg = typeof err === 'string'
? err
: err.response?.data?.error || err.response?.data?.message || err.message || "ERR_UNKNOWN";

if (errorMsg) {
if (i18n.exists(`backendErrors.${errorMsg}`)) {
toast.error(i18n.t(`backendErrors.${errorMsg}`), {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/hooks/useAuth.js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const useAuth = () => {
setIsAuth(true);
setUser(data.user);
} catch (err) {
toastError(err?.message);
toastError(err);
}
}
setLoading(false);
Expand Down Expand Up @@ -150,7 +150,7 @@ Entre em contato com o Suporte para mais informações! `);

//quebra linha
} catch (err) {
toastError(err?.message);
toastError(err);
setLoading(false);
}
};
Expand All @@ -170,7 +170,7 @@ Entre em contato com o Suporte para mais informações! `);
setLoading(false);
history.push("/login");
} catch (err) {
toastError(err?.message);
toastError(err);
setLoading(false);
}
};
Expand Down

0 comments on commit cfab86e

Please sign in to comment.