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

166
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
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