improvement: moved toast error logic into single function

This commit is contained in:
canove
2021-01-06 21:23:20 -03:00
parent 8ecd52e2b1
commit dcf1902fe1
21 changed files with 77 additions and 378 deletions

View File

@@ -0,0 +1,21 @@
import { toast } from "react-toastify";
import { i18n } from "../translate/i18n";
const toastError = err => {
const errorMsg = err.response?.data?.error;
if (errorMsg) {
if (i18n.exists(`backendErrors.${errorMsg}`)) {
toast.error(i18n.t(`backendErrors.${errorMsg}`), {
toastId: errorMsg,
});
} else {
toast.error(errorMsg, {
toastId: errorMsg,
});
}
} else {
toast.error("An error occurred!");
}
};
export default toastError;