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

430
Vistas
cancel axios request if it exceeds timeout and retry if the previous requests were timed out in nodejs

I have tried different ways to find the answer. If I use cancelToken library in axios(npm package). Once the request is cancelled, we can't retry the request. The request won't go to the next line(even after timeout) until it receives a response from the axios request.

I need an answer to cancel a request after timeout and should also retry the request incase of timeout.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Axios has an option "timeout", after that threshold it will cancel the request. So you can write something like this:

const TIMEOUT = 3000; // millisecods
let succeededResponse = null;

while(!succeededResponse) {
    try {
        succeededResponse = await axios.get("https://somewhere.any", { timeout: TIMEOUT });
    } catch(e) {
        // as axios will throw an error in case of timeout, you'll need this try-catch block
    }
}
// axios will request until it gets the response in the specified threshold
// here succeededResponse will have a value
about 4 years ago · Juan Pablo Isaza Denunciar
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