2022-01-06 01:26:15 +00:00
|
|
|
import { toast } from "react-toastify";
|
|
|
|
import { i18n } from "../translate/i18n";
|
|
|
|
|
2023-08-14 09:48:39 +00:00
|
|
|
const toastError = err => {
|
|
|
|
const errorMsg = err.response?.data?.message || err?.response?.data?.error || `${err?.message}`;
|
2022-01-06 01:26:15 +00:00
|
|
|
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;
|