The following client code calls a function
export async function verifyImage (image ) {
const data = new FormData();
...
let moderated;
await verifyImage (image).then(function (response) {
moderated = response;
});
console.log(moderated); //why is this always undefined?
and the function code is
await axios({
method: 'post',
url:'https://api.someapi.com/1.0/check.json',
data: data,
headers: { 'Content-Type': 'multipart/form-data' },
})
.then(function (response) {
// on success: handle response
console.log("resp in moderate pics")
console.log(sendVerifyResponse (response.data))
const moderated = sendVerifyResponse (response.data);
return moderated;
})
.catch(function (error) {
// handle error
if (error.response) console.log(error.response.data);
else console.log(error.message);
return false;
});
The following log shows the correct values
console.log(sendVerifyResponse (response.data))
But return moderated;
is always undefined.