Merge pull request #1555 from bluewave-labs/fix/fe/network-alerts

fix: fe axios error handler
This commit is contained in:
Alexander Holliday
2025-01-14 09:54:17 -08:00
committed by GitHub
2 changed files with 8 additions and 26 deletions

View File

@@ -110,7 +110,7 @@ const UptimeMonitors = () => {
setMonitorsSummary(summary);
} catch (error) {
createToast({
body: "Error fetching monitors",
body: error.message,
});
} finally {
setIsLoading(false);

View File

@@ -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();