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

102
Views
UnhandledPromiseRejection al devolver la promesa en la función async-await

Ya he buscado entre muchas preguntas de otros usuarios, pero todavía no puedo entender por qué mi función no funciona correctamente. Escribí este código:

 async function getFile(c, sourcePath, fileName, destPath) { return await new Promise((resolve, reject) => { c.cwd(sourcePath, function(err, currentDir) { // "c" is an instance of ftp module's class, "cwd" is one of its methods to change working directory err = new Error('trying to throw an error for testing the func'); if (err) reject(err); c.get(fileName, function(err, stream) { if (err) reject(err); stream.once('close', function() { resolve(); }); stream.pipe(fs.createWriteStream(destPath)); }); }); })); } (async function() { try { await getFile(c, '/path/to', 'file.xls', 'file.xls'); } catch (err) { throw err; } })();

El nodo devuelve un UnhandledPromiseRejectionWarning y no entiendo por qué. Devolví una promesa en la primera función y luego llamé a esa función en otra correctamente estructurada con la sintaxis async-await. ¿Qué está mal con mi código?

about 4 years ago · Juan Pablo Isaza
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!