I want to add retry logic to my javascript HTTP service, which internally uses Axios and returns promises. Goal is to retry fetch/post until it resolves or retry limit is exceeded. I came up with this draft (not working as it is)
fetchSomething(numRetry) {
if (!numRetry)
numRetry = 0
return new Promise(function(resolve, reject) {
axios.get('/services/rest/vopa/sanomaloki/virheet')
.then(response => resolve(response))
.catch(response => {
if (numRetry > FETCH_RETRY_LIMIT)
reject(response)
else
return fetchSomething(numRetry + 1)
})
});
}
As far as I know, calling fetchSomething in catch creates new resolve and reject functions, but I would like it to resolve or reject the original promise