1

I want to redirect to a specific page when Axios request catch an error. I have tried the history.push("/error") and also Redirect to = "/error". none of them worked. But the console.log(err) is working

Please anyone help me

const axiosInstance = axios.create({
baseURL: baseURL,
headers: {
    "Access-Control-Allow-Credentials": true,
    "access-control-allow-origin": "*",
    serviceKey: "",
},});
try {
    return await axiosInstance.get(path, {
        params: "",
        headers: {
            clientClaim: claim,
        },
    });
} catch (err) {
    if (err.response) {
        if (err.response.status === 500) {
            // Here I want to redirect to ServerError.js page
            // console.log(err.response.status) is working
        }
    } else if (err.request) {
        console.log("I got request Error", err.request);
    } else {
        console.log("Some Error");
    }
}

0 Answers0