I am new to Node.js and Javascript, I used npm package retry to send requests to server.
const retry = require('retry');
async function HandleReq() {
//Some code
return await SendReqToServer();
}
async function SendReqToServer() {
operation.attempt(async (currentAttempt) =>{
try {
let resp = await axios.post("http://localhost:5000/api/", data, options);
return resp.data;
} catch (e) {
if(operation.retry(e)) {throw e;}
}
});
}
I get empty response because SendReqToServer returns a promise before function passed to operation.attempt resolves the promise.
How to solve this issue ?
SendReqToServerdoesn't return anything, is this on purpose?return resp.datareturns data to the.attemptcallback. You'll want to returnoperation.attempt(...)to return the value toSendReqToServer.SendReqToServerreturns a promise.operation.attempt()- without actually waiting for anything - since there's basically an implicitreturn undefined;at the end of the function.SendReqToServerresolves toundefined, I assume this is not on purpose