Currently, I am utilizing axios to handle my API calls. One thing that I want to achieve is checking the status of the response received from the api and potentially redirecting to a 404 page based on that.
const api = axios.create({
headers: {
common: {
'Content-Type': 'application/json'
},
post: {
}
}
});
api.interceptors.response.use(
...
(error) => {
const code = parseInt(error.response && error.response.status)
if (code === 404) {
console.log("responsive",error)
if(data){
data.forEach(itemError => {
toast.error(itemError, {
theme: 'colored',
});
});
}else{
//Even though I attempted to redirect to the 404 page here, unfortunately it did not work as expected.
//return window.location.href = '/404';
}
...
I'm currently facing the challenge of figuring out how to successfully implement the redirection within this context.