I have an async function that is returning undefined when I console.log the response. The code that calls the function is inside a Lambda function that is async itself hence the desire to use await
. The sendRequest function is outside that lambda function though is in the same file.
// main.js
async sendRequest ...
exports.foobar = async ...
Below is the code that calls the function (which is inside another function).
const response = await sendRequest(url)
console.log(response)
sendRequest async function that returns undefined
async function sendRequest (url) {
let code;
request({ url, timeout: 20000 }, function(error, response, body) {
if (error == 'ENOTFOUND' || error == 'ETIMEDOUT') {
response.statusCode = 500;
}
code = response.statusCode
return {
code,
error
}
});
}