Is there a way to redirect the page in an axios interceptor when dealing with server-side rendering limitations?
Unfortunately, I am unable to access the server side context in the axios interceptor. I have tried using next/router but it only works on the client side.
Any suggestions on how to solve this issue?
Here is the function being executed in the axios interceptor:
// customAxios.ts
const customAxios = axios.create();
customAxios.interceptors.response.use((response) => response, responseErrorHandler);
// responseErrorHandler.ts
const responseErrorHandler = (error: AxiosError): Promise<AxiosError> => {
if (error.response) {
if (error.message === TIMEOUT_MESSAGE) {
if (typeof window === 'undefined') {
// Redirect to /503 page in server side rendering
} else {
window.location.href = '/503';
}
}
}
return Promise.reject(error);
}