implementation errorHandler

This commit is contained in:
Amirhossein Mahmoodi
2023-08-09 12:38:08 +03:30
parent 842f1029c1
commit 3726d2ec38
22 changed files with 235 additions and 79 deletions

View File

@@ -2,7 +2,7 @@ import DangerousIcon from "@mui/icons-material/Dangerous";
import {Box, Typography} from "@mui/material";
import {toast} from "react-toastify";
const ErrorNotification = (directionApp, t, status, message) => {
const ErrorNotification = (t, status, message) => {
toast(
() => (
<>
@@ -29,7 +29,6 @@ const ErrorNotification = (directionApp, t, status, message) => {
</>
),
{
position: directionApp === "ltr" ? "top-left" : "top-right",
autoClose: false,
closeOnClick: false,
draggable: false,

View File

@@ -0,0 +1,11 @@
import {toast} from "react-toastify";
const PendingNotification = (t) => {
toast(t("notifications.pending"), {
autoClose: false,
closeOnClick: false,
draggable: false,
});
};
export default PendingNotification;

View File

@@ -2,7 +2,7 @@ import BeenhereIcon from "@mui/icons-material/Beenhere";
import {Box, Typography} from "@mui/material";
import {toast} from "react-toastify";
const SuccessNotification = (directionApp, t, status) => {
const SuccessNotification = (t, status) => {
toast(
() => (
<>
@@ -30,7 +30,6 @@ const SuccessNotification = (directionApp, t, status) => {
</>
),
{
position: directionApp === "ltr" ? "top-left" : "top-right",
autoClose: 3000,
hideProgressBar: true,
pauseOnHover: true,

View File

@@ -2,7 +2,7 @@ import DangerousIcon from "@mui/icons-material/Dangerous";
import {Box, Typography} from "@mui/material";
import {toast} from "react-toastify";
const UploadFileNotification = (directionApp, t) => {
const UploadFileNotification = (t) => {
toast(
({closeToast}) => (
<>
@@ -26,7 +26,6 @@ const UploadFileNotification = (directionApp, t) => {
</>
),
{
position: directionApp === "ltr" ? "top-left" : "top-right",
autoClose: false,
closeOnClick: false,
draggable: false,

View File

@@ -2,7 +2,7 @@ import ReportIcon from "@mui/icons-material/Report";
import {Box, Typography} from "@mui/material";
import {toast} from "react-toastify";
const WarningNotification = (directionApp, t, status) => {
const WarningNotification = (t, status) => {
toast(
() => (
<>
@@ -30,7 +30,6 @@ const WarningNotification = (directionApp, t, status) => {
</>
),
{
position: directionApp === "ltr" ? "top-left" : "top-right",
autoClose: false,
closeOnClick: false,
draggable: false,

View File

@@ -3,37 +3,36 @@ import ErrorNotification from "./ErrorNotification";
import WarningNotification from "./WarningNotification";
import SuccessNotification from "./SuccessNotification";
const Notifications = async (directionApp, t, response) => {
const Notifications = async (t, response) => {
const {status, data} = response != undefined ? response : ""
toast.dismiss();
switch (status) {
case 200:
SuccessNotification(directionApp, t, status);
SuccessNotification(t, status);
break;
case 400:
ErrorNotification(directionApp, t, status);
ErrorNotification(t, status);
break;
case 401:
ErrorNotification(directionApp, t, status);
ErrorNotification(t, status);
break;
case 403:
ErrorNotification(directionApp, t, status);
ErrorNotification(t, status);
break;
case 422:
ErrorNotification(directionApp, t, status, data.message);
ErrorNotification(t, status, data.message);
break;
case 500:
WarningNotification(directionApp, t, status);
WarningNotification(t, status);
break;
case 503:
WarningNotification(directionApp, t, status);
WarningNotification(t, status);
break;
case 504:
WarningNotification(directionApp, t, status);
WarningNotification(t, status);
break;
default:
toast(t("notifications.pending"), {
position: directionApp === "ltr" ? "top-left" : "top-right",
autoClose: false,
closeOnClick: false,
draggable: false,
@@ -47,9 +46,9 @@ export default Notifications;
/*
usage document
** for pending use ( Notifications(directionApp, t, undefined) ) this before your request.
** for success use ( Notifications(directionApp, t, response) ) this inside .then() of your request.
** for Error and Warning use ( Notifications(directionApp, t, error.response) ) this inside .catche() of your request.
** for pending use ( Notifications( t, undefined) ) this before your request.
** for success use ( Notifications( t, response) ) this inside .then() of your request.
** for Error and Warning use ( Notifications( t, error.response) ) this inside .catche() of your request.
end usage document
*/