Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
Promete la recursividad con axios, reintentando catch

Todavía soy bastante nuevo en Promises y me gustaría alguna aclaración.

Para algún contexto, estoy tratando de obtener un archivo de una URL. El archivo se almacena usando IPFS y cuando hay un tiempo de espera, me gustaría intentar llamar a axios.get() nuevamente.

Mi problema actual es que parece que el archivo se está descargando, pero la función rara vez devuelve algo, parece que la descarga es muy lenta, sin embargo, si abro el enlace directamente, obtengo el archivo al instante, lo que me hace pensar que hay algo mal con mis promesas, aunque no se ejecutan then() ni catch() . Mi código actual es el siguiente:

 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 answers
Answer question

0

Hay un complemento para axios llamado axios-retry que puede usar:

 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 Report

0

Además del complemento axios-retry, sería útil aumentar el tiempo de espera predeterminado de axios, en caso de que no sea suficiente para leer el archivo.

 instance.get('/yourRequestedURL', {
 timeout: 15000 //Try to give a little more than the timeout of the file
});
almost 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!