I am currently using axios in conjunction with TypeScript.
Below is a simple axios interceptor that I have implemented:
// Adding a response interceptor
axios.interceptors.response.use((response: AxiosResponse<any>) => {
// Processing response data
return response;
}, (error: any) => {
// Handling response error
// In this case, "error.response" is undefined.
return Promise.reject(error);
});
My objective is to redirect to another location (specifically an identity server SSO page) when a user is not authenticated.
When a call is made to my API and it returns a 302 status code due to authentication failure, the axios interceptor does not automatically redirect to the appropriate location.
Even though manual redirection would be acceptable, the issue lies with "error.response" returning as undefined.
Therefore, I am facing difficulty in determining how to proceed with the redirection, as the status code cannot be detected without the presence of "error.response".
On inspecting the network tab, the information displayed is as follows:
No response data available in the Response tab...
https://i.sstatic.net/VJrr8.png
Any insights on what might be going wrong in this scenario?