mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-15 06:09:44 -06:00
Merge pull request #1555 from bluewave-labs/fix/fe/network-alerts
fix: fe axios error handler
This commit is contained in:
@@ -110,7 +110,7 @@ const UptimeMonitors = () => {
|
||||
setMonitorsSummary(summary);
|
||||
} catch (error) {
|
||||
createToast({
|
||||
body: "Error fetching monitors",
|
||||
body: error.message,
|
||||
});
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
|
||||
@@ -27,7 +27,13 @@ class NetworkService {
|
||||
this.axiosInstance.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
this.handleError(error);
|
||||
if (!error.request && error.response && error.response.status === 401) {
|
||||
dispatch(clearAuthState());
|
||||
dispatch(clearUptimeMonitorState());
|
||||
navigate("/login");
|
||||
} else if (error.request && !error.response) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
@@ -37,30 +43,6 @@ class NetworkService {
|
||||
this.axiosInstance.defaults.baseURL = url;
|
||||
};
|
||||
|
||||
handleError(error) {
|
||||
if (error.response) {
|
||||
const status = error.response.status;
|
||||
if (status === 401) {
|
||||
this.dispatch(clearAuthState());
|
||||
this.dispatch(clearUptimeMonitorState());
|
||||
this.navigate("/login");
|
||||
} else if (status >= 500) {
|
||||
// Display toast for server errors to all users
|
||||
createToast({
|
||||
variant: "error",
|
||||
body: "Checkmate server is not running or has issues. Please check.",
|
||||
});
|
||||
}
|
||||
} else if (error.request) {
|
||||
// Show a toast informing the user the server didn't respond
|
||||
createToast({
|
||||
variant: "error",
|
||||
body: "The server did not respond. Please check your network or try again later.",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cleanup() {
|
||||
if (this.unsubscribe) {
|
||||
this.unsubscribe();
|
||||
|
||||
Reference in New Issue
Block a user