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

@@ -20,7 +20,7 @@ const DashboardChangePasswordComponent = () => {
const {directionApp} = useDirection();
const handleSubmit = (values, {setSubmitting, resetForm}) => {
Notifications(directionApp, t);
Notifications(t);
axios
.post(
CHANGE_PASSWORD,
@@ -35,12 +35,12 @@ const DashboardChangePasswordComponent = () => {
)
.then((response) => {
toast.dismiss(pendingToast); // Dismiss the pending toast notification
Notifications(directionApp, t, response);
Notifications(t, response);
resetForm();
})
.catch((error) => {
toast.dismiss(pendingToast); // Dismiss the pending toast notification
Notifications(directionApp, t, error.response);
Notifications(t, error.response);
})
.finally(() => {
setSubmitting(false); // Set `setSubmitting` to false after the API request completes

View File

@@ -20,7 +20,7 @@ const DashboardEditProfile = () => {
const {directionApp} = useDirection();
const editAvatar = async (avatar) => {
Notifications(directionApp, t);
Notifications(t);
try {
const formData = new FormData();
@@ -37,7 +37,7 @@ const DashboardEditProfile = () => {
},
});
} catch (error) {
Notifications(directionApp, t, error.response);
Notifications(t, error.response);
throw error;
}
};
@@ -55,13 +55,13 @@ const DashboardEditProfile = () => {
// });
// })
// .then((response) => {
// Notifications(directionApp, t, response);
// Notifications( t, response);
// getUser((data) => {
// changeUser(data);
// });
// })
// .catch((error) => {
// Notifications(directionApp, t, error.response);
// Notifications( t, error.response);
// })
// .finally(() => {
// setSubmitting(false);
@@ -75,13 +75,13 @@ const DashboardEditProfile = () => {
// },
// })
// .then((response) => {
// Notifications(directionApp, t, response);
// Notifications( t, response);
// getUser((data) => {
// changeUser(data);
// });
// })
// .catch((error) => {
// Notifications(directionApp, t, error.response);
// Notifications( t, error.response);
// })
// .finally(() => {
// setSubmitting(false);

View File

@@ -21,17 +21,17 @@ const TableRowActions = ({row, mutate, fetchUrl}) => {
setOpenConfirmDialog(false);
};
const confirmData = useCallback((url, rowID, values) => {
Notifications(directionApp, t, undefined)
Notifications(t, undefined)
axios
.post(`${url}/${rowID}`, values, {
headers: {authorization: `Bearer ${token}`},
})
.then((response) => {
Notifications(directionApp, t, response);
Notifications(t, response);
mutate(fetchUrl)
})
.catch((error) => {
Notifications(directionApp, t, error.response);
Notifications(t, error.response);
});
}, []);
// End Confirm
@@ -43,17 +43,17 @@ const TableRowActions = ({row, mutate, fetchUrl}) => {
};
const rejectData = useCallback((url, rowID, values) => {
Notifications(directionApp, t)
Notifications(t)
axios
.post(`${url}/${rowID}`, values, {
headers: {authorization: `Bearer ${token}`},
})
.then((response) => {
Notifications(directionApp, t, response);
Notifications(t, response);
mutate(fetchUrl)
})
.catch((error) => {
Notifications(directionApp, t, error.response);
Notifications(t, error.response);
});
}, []);
// End Reject

View File

@@ -21,17 +21,17 @@ const TableRowActions = ({row, mutate, fetchUrl}) => {
setOpenConfirmDialog(false);
};
const confirmData = useCallback((url, rowID, values) => {
Notifications(directionApp, t, undefined)
Notifications(t, undefined)
axios
.post(`${url}/${rowID}`, values, {
headers: {authorization: `Bearer ${token}`},
})
.then((response) => {
Notifications(directionApp, t, response);
Notifications(t, response);
mutate(fetchUrl)
})
.catch((error) => {
Notifications(directionApp, t, error.response);
Notifications(t, error.response);
});
}, []);
// End Confirm
@@ -43,17 +43,17 @@ const TableRowActions = ({row, mutate, fetchUrl}) => {
};
const rejectData = useCallback((url, rowID, values) => {
Notifications(directionApp, t)
Notifications(t)
axios
.post(`${url}/${rowID}`, values, {
headers: {authorization: `Bearer ${token}`},
})
.then((response) => {
Notifications(directionApp, t, response);
Notifications(t, response);
mutate(fetchUrl)
})
.catch((error) => {
Notifications(directionApp, t, error.response);
Notifications(t, error.response);
});
}, []);
// End Reject

View File

@@ -21,17 +21,17 @@ const TableRowActions = ({row, mutate, fetchUrl}) => {
setOpenConfirmDialog(false);
};
const confirmData = useCallback((url, rowID, values) => {
Notifications(directionApp, t, undefined)
Notifications(t, undefined)
axios
.post(`${url}/${rowID}`, values, {
headers: {authorization: `Bearer ${token}`},
})
.then((response) => {
Notifications(directionApp, t, response);
Notifications(t, response);
mutate(fetchUrl)
})
.catch((error) => {
Notifications(directionApp, t, error.response);
Notifications(t, error.response);
});
}, []);
// End Confirm
@@ -43,17 +43,17 @@ const TableRowActions = ({row, mutate, fetchUrl}) => {
};
const rejectData = useCallback((url, rowID, values) => {
Notifications(directionApp, t)
Notifications(t)
axios
.post(`${url}/${rowID}`, values, {
headers: {authorization: `Bearer ${token}`},
})
.then((response) => {
Notifications(directionApp, t, response);
Notifications(t, response);
mutate(fetchUrl)
})
.catch((error) => {
Notifications(directionApp, t, error.response);
Notifications(t, error.response);
});
}, []);
// End Reject

View File

@@ -21,17 +21,17 @@ const TableRowActions = ({row, mutate, fetchUrl}) => {
setOpenConfirmDialog(false);
};
const confirmData = useCallback((url, rowID, values) => {
Notifications(directionApp, t, undefined)
Notifications(t, undefined)
axios
.post(`${url}/${rowID}`, values, {
headers: {authorization: `Bearer ${token}`},
})
.then((response) => {
Notifications(directionApp, t, response);
Notifications(t, response);
mutate(fetchUrl)
})
.catch((error) => {
Notifications(directionApp, t, error.response);
Notifications(t, error.response);
});
}, []);
// End Confirm
@@ -43,17 +43,17 @@ const TableRowActions = ({row, mutate, fetchUrl}) => {
};
const rejectData = useCallback((url, rowID, values) => {
Notifications(directionApp, t)
Notifications(t)
axios
.post(`${url}/${rowID}`, values, {
headers: {authorization: `Bearer ${token}`},
})
.then((response) => {
Notifications(directionApp, t, response);
Notifications(t, response);
mutate(fetchUrl)
})
.catch((error) => {
Notifications(directionApp, t, error.response);
Notifications(t, error.response);
});
}, []);
// End Reject

View File

@@ -21,17 +21,17 @@ const TableRowActions = ({row, mutate, fetchUrl}) => {
setOpenConfirmDialog(false);
};
const confirmData = useCallback((url, rowID, values) => {
Notifications(directionApp, t, undefined)
Notifications(t, undefined)
axios
.post(`${url}/${rowID}`, values, {
headers: {authorization: `Bearer ${token}`},
})
.then((response) => {
Notifications(directionApp, t, response);
Notifications(t, response);
mutate(fetchUrl)
})
.catch((error) => {
Notifications(directionApp, t, error.response);
Notifications(t, error.response);
});
}, []);
// End Confirm
@@ -43,17 +43,17 @@ const TableRowActions = ({row, mutate, fetchUrl}) => {
};
const rejectData = useCallback((url, rowID, values) => {
Notifications(directionApp, t)
Notifications(t)
axios
.post(`${url}/${rowID}`, values, {
headers: {authorization: `Bearer ${token}`},
})
.then((response) => {
Notifications(directionApp, t, response);
Notifications(t, response);
mutate(fetchUrl)
})
.catch((error) => {
Notifications(directionApp, t, error.response);
Notifications(t, error.response);
});
}, []);
// End Reject