I'm trying to make a request to this MailGun endpoint. I need this function to return an AcessResponse object but I having trouble returning the response before my function gets to return {data: {info: "Bad test"}}
. How do I wait to return anything until my request finishes? I've tried not including a return statement at the end of this function but then it errors saying I need to return something. TIA.
access: async (identifier: string): Promise<AccessResponse> => {
var options = {
url: 'https://api.mailgun.net/v3/lists/pages',
auth: {
'user': 'api',
'pass': '*********************************'
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
return {data: response.body};
}
}
request(options, callback);
return {data: {info: "Bad test"}}
},