mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 11:49:19 +00:00
improvement: moved toast error logic into single function
This commit is contained in:
21
frontend/src/errors/toastError.js
Normal file
21
frontend/src/errors/toastError.js
Normal 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;
|
||||
Reference in New Issue
Block a user