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

@@ -21,6 +21,7 @@ import Container from "@material-ui/core/Container";
import { i18n } from "../../translate/i18n";
import api from "../../services/api";
import toastError from "../../errors/toastError";
// const Copyright = () => {
// return (
@@ -47,7 +48,7 @@ const useStyles = makeStyles(theme => ({
backgroundColor: theme.palette.secondary.main,
},
form: {
width: "100%", // Fix IE 11 issue.
width: "100%",
marginTop: theme.spacing(3),
},
submit: {
@@ -78,16 +79,7 @@ const SignUp = () => {
toast.success(i18n.t("signup.toasts.success"));
history.push("/login");
} catch (err) {
const errorMsg = err.response?.data?.error;
if (errorMsg) {
if (i18n.exists(`backendErrors.${errorMsg}`)) {
toast.error(i18n.t(`backendErrors.${errorMsg}`));
} else {
toast.error(err.response.data.error);
}
} else {
toast.error("Unknown error");
}
toastError(err);
}
};