Merge pull request #1555 from bluewave-labs/fix/fe/network-alerts
fix: fe axios error handler
This commit is contained in:
2 files changed
+8
-26
No files matched your search
@@ -110,7 +110,7 @@ const UptimeMonitors = () => {
|
|||||||
setMonitorsSummary(summary);
|
setMonitorsSummary(summary);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createToast({
|
createToast({
|
||||||
body: "Error fetching monitors",
|
body: error.message,
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
|
|||||||
@@ -27,7 +27,13 @@ class NetworkService {
|
|||||||
this.axiosInstance.interceptors.response.use(
|
this.axiosInstance.interceptors.response.use(
|
||||||
(response) => response,
|
(response) => response,
|
||||||
(error) => {
|
(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);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -37,30 +43,6 @@ class NetworkService {
|
|||||||
this.axiosInstance.defaults.baseURL = url;
|
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() {
|
cleanup() {
|
||||||
if (this.unsubscribe) {
|
if (this.unsubscribe) {
|
||||||
this.unsubscribe();
|
this.unsubscribe();
|
||||||
|
|||||||
Reference in new issue
Block a user