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

165
Vistas
Promise recursion with axios, retrying on catch

I'm still quite new to Promises and would like some clarification.

For some context, I'm trying to get a file from an URL. The file is stored using IPFS and when there's a timeout I would like to try and call axios.get() again.

My current problem is, that it looks like the file is being downloaded but the function rarely returns anything, it looks like the download is super slow, however if I open the link directly I get the file instantly, making me think there's something wrong with my promises, even though no then() nor catch() is ran. My current code is as follows:

const getIPFSMedia = (url) => {
  return axios.get(url, { responseType: 'blob' }).then((response) => {
    return URL.createObjectURL(response.data);
  }).catch((e) => {
    if (e.message === GET_IPFS_TIMED_OUT) {
      return getIPFSMedia(url);
    } else {
      console.log(e.message);
    }
  });
}

const fetchData = async() => {
  const image = await getIPFSMedia(url); // Slow or rarely returns, but when it does it has my file in it
  console.log(image)
}
almost 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

There is a plug-in for axios called axios-retry which you can use:

import axiosRetry from 'axios-retry';

axiosRetry(axios, { retries: 1 });

axios.get(url); // It will retry one time if the request fail.
almost 4 years ago · Santiago Trujillo Denunciar

0

Additional to the axios-retry plugin, it would be helpful if you increase the axios default timeout, in case it is not enough to read the file.

instance.get('/yourRequestedURL', {
  timeout: 15000 //Try to give a little more than the timeout of the file
});
almost 4 years ago · Santiago Trujillo 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