axios-retry with custom retry option

1.2k Views Asked by At

I'm having issues with axios retry. It is not retrying, it returns response after first time it fails.

await axios.get(`${URL}/test`, {
    'axios-retry': {
        retries: 3
    },
    headers: {
        'Content-Type': 'application/json',
    }
})
.then(async (response) => {
    //console.log(response);
    return res.json(response.data);
})
.catch((err) => {
    console.log("Error: " + err);
    return res.json("ERROR");
});

At the first error console log, it stops and return the ERROR. I also, would like to set the some retry "custom" conditions. For example, if the response.data is an empty string, I would like to retry. Is it possible?

Thanks

0

There are 0 best solutions below