Compare commits
No commits in common. "8024b8070b5cfd7e32c72835e66b6576f515f868" and "820c979c94ac16d5979ee7d746c24ab87be3d4cf" have entirely different histories.
8024b8070b
...
820c979c94
@ -1,9 +1,40 @@
|
|||||||
import { type AxiosError, type AxiosResponse } from "axios";
|
|
||||||
import Project from "@/ApiClasses/Project";
|
import Project from "@/ApiClasses/Project";
|
||||||
import SectionCell from "@/ApiClasses/SectionCell";
|
import SectionCell from "@/ApiClasses/SectionCell";
|
||||||
import { axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler } from "@/services/api"
|
import {
|
||||||
|
axiosInstance,
|
||||||
|
defaultApiErrorHandler,
|
||||||
|
defaultApiSuccessHandler,
|
||||||
|
} from "@/services/api";
|
||||||
|
|
||||||
|
axiosInstance.interceptors.response.use(
|
||||||
|
(response) => response, // Directly return successful responses.
|
||||||
|
async (error) => {
|
||||||
|
const originalRequest = error.config;
|
||||||
|
if (
|
||||||
|
((error.response && error.response.status === 401) ||
|
||||||
|
error.code == "ERR_NETWORK") &&
|
||||||
|
!originalRequest._retry &&
|
||||||
|
store.authenticated
|
||||||
|
) {
|
||||||
|
originalRequest._retry = true; // Mark the request as retried to avoid infinite loops.
|
||||||
|
try {
|
||||||
|
await store.refreshUserToken();
|
||||||
|
// Update the authorization header with the new access token.
|
||||||
|
axiosInstance.defaults.headers.common["Authorization"] =
|
||||||
|
`Bearer ${store.user.token}`;
|
||||||
|
return axiosInstance(originalRequest); // Retry the original request with the new access token.
|
||||||
|
} catch (refreshError) {
|
||||||
|
// Handle refresh token errors by clearing stored tokens and redirecting to the login page.
|
||||||
|
console.error("Token refresh failed:", refreshError);
|
||||||
|
localStorage.removeItem("accessToken");
|
||||||
|
localStorage.removeItem("refreshToken");
|
||||||
|
router.push("/login");
|
||||||
|
return Promise.reject(refreshError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.reject(error); // For all other errors, return the error as is.
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// Entrepreneurs API
|
// Entrepreneurs API
|
||||||
function requestProjectCreation(
|
function requestProjectCreation(
|
||||||
@ -30,12 +61,12 @@ function requestProjectCreation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addSectionCell(
|
function addSectionCell(
|
||||||
sectionCellDetails: SectionCell, // Replace 'any' with a proper type for section cell details if available
|
sectionCellDetails: SectionCell,
|
||||||
onSuccessHandler?: (response: AxiosResponse) => void,
|
onSuccessHandler?: (response: AxiosResponse) => void,
|
||||||
onErrorHandler?: (error: AxiosError) => void
|
onErrorHandler?: (error: AxiosError) => void
|
||||||
): void {
|
): void {
|
||||||
axiosInstance
|
axiosInstance
|
||||||
.post("/entrepreneur/sectionCells", sectionCellDetails.toPlainObject())
|
.post("/entrepreneur/sectionCells", sectionCellDetails.toPlainObject()) // <-- Ici
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (onSuccessHandler) {
|
if (onSuccessHandler) {
|
||||||
onSuccessHandler(response);
|
onSuccessHandler(response);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user