Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

250
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda