Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda