Merge branch 'develop' into fix/be/uptime-duration
This commit is contained in:
commit
70898da69d
2 files changed
+30
-8
No files matched your search
@@ -3,6 +3,8 @@ const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
|
|||||||
const FALLBACK_BASE_URL = "http://localhost:5000/api/v1";
|
const FALLBACK_BASE_URL = "http://localhost:5000/api/v1";
|
||||||
import { clearAuthState } from "../Features/Auth/authSlice";
|
import { clearAuthState } from "../Features/Auth/authSlice";
|
||||||
import { clearUptimeMonitorState } from "../Features/UptimeMonitors/uptimeMonitorsSlice";
|
import { clearUptimeMonitorState } from "../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
|
import { createToast } from "./toastUtils";
|
||||||
|
|
||||||
class NetworkService {
|
class NetworkService {
|
||||||
constructor(store, dispatch, navigate) {
|
constructor(store, dispatch, navigate) {
|
||||||
this.store = store;
|
this.store = store;
|
||||||
@@ -25,11 +27,7 @@ class NetworkService {
|
|||||||
this.axiosInstance.interceptors.response.use(
|
this.axiosInstance.interceptors.response.use(
|
||||||
(response) => response,
|
(response) => response,
|
||||||
(error) => {
|
(error) => {
|
||||||
if (error.response && error.response.status === 401) {
|
this.handleError(error);
|
||||||
dispatch(clearAuthState());
|
|
||||||
dispatch(clearUptimeMonitorState());
|
|
||||||
navigate("/login");
|
|
||||||
}
|
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -39,6 +37,30 @@ 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();
|
||||||
|
|||||||
Generated
+3
-3
@@ -5774,9 +5774,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/mongoose": {
|
"node_modules/mongoose": {
|
||||||
"version": "8.9.3",
|
"version": "8.9.4",
|
||||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.9.3.tgz",
|
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.9.4.tgz",
|
||||||
"integrity": "sha512-G50GNPdMqhoiRAJ/24GYAzg13yxXDD3FOOFeYiFwtHmHpAJem3hxbYIxAhLJGWbYEiUZL0qFMu2LXYkgGAmo+Q==",
|
"integrity": "sha512-DndoI01aV/q40P9DiYDXsYjhj8vZjmmuFwcC3Tro5wFznoE1z6Fe2JgMnbLR6ghglym5ziYizSfAJykp+UPZWg==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bson": "^6.10.1",
|
"bson": "^6.10.1",
|
||||||
|
|||||||
Reference in new issue
Block a user