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

105
Views
Solicitud POST... UnhandledPromiseRejectionWarning: Rechazo de promesa no manejado

Al hacer una solicitud de publicación me sale este error:

UnhandledPromiseRejectionWarning: Rechazo de promesa no controlado.

Si alguien pudiera explicar por qué sucede esto, se lo agradecería :) Gracias.

ACTUALIZAR

Entonces, este código se publica con éxito. Pero, cuando elimino el comentario del código de validación, aparece el mismo error...

 router.post("/", async (req, res) => { //let client = validate(req.body); //if (client.error) { //res.status(400).json(result.error); //return; //} let client = new Client(req.body); try { let savedClient = await client.save(); res.location(`/${savedClient._id}`).status(201).json(savedClient); } catch (error) { res.status(500).json(savedClient.error); } });
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

No veo dónde inicializas savedClient y creo que tu error radica en tu captura. Estás haciendo referencia a un objeto ( savedClient ) que no parece estar dentro del alcance.

Prueba esto:

 router.post("/", async (req, res) => { let client = new Client(req.body); try { let savedClient = await client.save(); res.location(`/${savedClient._id}`).status(201).json(savedClient); } catch (error) { console.log(error) res.status(500).json(error); } });
about 4 years ago · Juan Pablo Isaza Report

0

quizás

 let savedClient = await client.save();
about 4 years ago · Juan Pablo Isaza Report

0

Creo que debería ser

 ... } catch (error) { res.status(500).json(savedClient.error); }

porque el error de rechazo de la promesa debe ser capturado por la instrucción try/catch.

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