I have the following code:
getData = async function (afgJSON) {
console.log("step 2")
await axios.post(process.env.afgEndPoint, afgJSON, {
headers: headers
})
.then((response) => {
console.log("step 3")
return response.data
})
.catch((e) => {
console.log("step 3")
return e.response.data
})
}
Which I call as this:
console.log("step 1")
let afgResponse = await common.getData(afgJSON);
console.log("step 4")
console.log(afgResponse)
afgResponse always is undefined, and the console.logs show the right order:
step 1
step 2
step 3
step 4
undefined
... but if I console.log response.data (.then), the response is fine.
I was reading other posts at stackoverflow about .then => with Axios but I still cant figure this out.
Thanks.