Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
How to return response body before function hits other return statement?

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"}}
  },
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!