Why is it not possible to call resolve in the catch block?
I wanted to catch a failed request and attempt it again in the catch block, but I am encountering an issue where resolve is not defined. I am confused since I am inside of the promise, so why is it not allowing me to call resolve?
module.exports.makeRequest = function(ID, requestAttempts) {
return new Promise(function(resolve, reject) {
request.get(url, {json:true}, function(err, res) {
if(err || res.body.error_code)
reject(err || res.body)
else
resolve(res.body)
})
})
.catch(function(error) {
if (requestAttempts <= 0) {
reject(error);
}
console.log("Error:", error, `\n Try to repeat the request (attempts left: ${requestAttempts})`);
resolve(makeRequest(ID, requestAttempts - 1));
});
}