CFE-6 debugging notifications

This commit is contained in:
2023-10-29 17:42:31 +03:30
parent ae5313ef2d
commit 3be39d451c
12 changed files with 89 additions and 114 deletions

View File

@@ -1,17 +1,22 @@
import ErrorNotification from "@/core/components/notifications/ErrorNotification";
import WarningNotification from "@/core/components/notifications/WarningNotification";
import {toast} from "react-toastify";
import Notifications from "@/core/components/notifications";
export const errorSetting = (t, notification) => {
if (notification) toast.dismiss();
if (notification) {
toast.dismiss()
}
}
export const errorRequest = (t, notification) => {
if (notification) toast.dismiss();
if (notification) {
toast.dismiss()
}
}
export const errorResponse = (response, clearToken, t, notification) => {
if (notification) toast.dismiss();
if (notification) {
toast.dismiss()
}
if (isServerError(response.status)) {
errorServer(response, t, notification)
} else if (isClientError(response.status)) {
@@ -20,13 +25,13 @@ export const errorResponse = (response, clearToken, t, notification) => {
}
const errorServer = (response, t, notification) => {
if (notification) WarningNotification(t, response.status);
if (notification) Notifications("warning", t, response.status);
}
const errorClient = (response, clearToken, t, notification) => {
switch (response.status) {
case 401:
clearToken()
if (notification) ErrorNotification(t, response.status)
if (notification) Notifications("error", t, response.status);
break;
case 422:
if ('type' in response.data) {
@@ -36,10 +41,10 @@ const errorClient = (response, clearToken, t, notification) => {
errorValidation(response, t, notification)
break;
case 429:
if (notification) ErrorNotification(t, response.status)
if (notification) Notifications("error", t, response.status);
break
default:
if (notification) ErrorNotification(t, response.status)
if (notification) Notifications("error", t, response.status);
break
}
}
@@ -48,7 +53,7 @@ const isServerError = status => status >= 500 && status <= 599;
const isClientError = status => status >= 400 && status <= 499;
const errorLogic = (response, t, notification) => {
if (notification) ErrorNotification(t, response.status, response.data.message)
if (notification) Notifications("error", t, response.status, response.data.message);
}
const errorValidation = (response, t, notification) => {
if (notification) {
@@ -56,7 +61,7 @@ const errorValidation = (response, t, notification) => {
const errorsArray = response.data.errors
errorsMap.map((item, index) => {
ErrorNotification(t, response.status, errorsArray[item][0]);
Notifications("error", t, errorsArray[item][0], response.data.message);
})
}
}