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

145
Views
Captura de errores de promesa de un bucle

Necesito llamar a varias promesas dentro de un bucle for, pero me da una unhandled promise exception durante cada ejecución. La forma de solucionar esto es devolver la segunda promesa, de esta forma se ejecutaría el último catch y funcionaría sin errores, pero - la segunda y más iteraciones no se ejecutarían.

 const doFirstThing = () => { return new Promise((resolve, reject) => { setTimeout(() => (resolve(['a', 'b', 'c'])), 1000); }); } const doSecondThing = () => { return new Promise((resolve, reject) => { setTimeout(() => (reject('test')), 500); // reject here }); } doFirstThing() .then(results => { results.forEach(result => { doSecondThing(result) .then(() => console.log(result, 'done')); }); }) .catch(error => console.log(error));

¿Cómo puedo lidiar con esto?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Para evitar la cadena de unhandled promise exception .catch() a lat .then() ; sustituir usando Promise.all() y .map() por .forEach()

 const doFirstThing = () => { return new Promise((resolve, reject) => { setTimeout(() => (resolve(['a', 'b', 'c'])), 1000); }) } const doSecondThing = (r) => { return new Promise((resolve, reject) => { setTimeout(() => (reject('test')), 500); // reject here }) } doFirstThing() .then(results => { return Promise.all(results.map(result => { return doSecondThing(result) })); }) .then((result) => console.log(result, 'done')) .catch(error => console.log(`err:${error}`));

over 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!