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

182
Views
Unhandled promise rejection when iterating over async calls before awaiting all

I've encountered a weird problem I cant find an explanation to anywhere. In the following code, I'm trying to get a number of position entities, each by id using and API call.

Some id requests might end up with an 404, and I dont mind that, that's why I'm using Promise.allSettled()

    const positionsPromises = idList.map((id) => {
      return this.positionRepository.getPositionById(id);
    });

    const positions = await Promise.allSettled(positionsPromises);

This generally works, but for non-existing ids (or any other errors), I get the famous node logs for UnhandledPromiseRejectionWarning

however... when taking the same .map() code and just throwing it directly inside Promise.allSettled() I get no such things, and it works as expected- some resolve, some reject, and I can iterate over positions to check each one.

    const positions = await Promise.allSettled(
      idList.map((id) => {
        return this.positionRepository.getPositionById(id);
      }),
    );

Why is this happening? Am I doing something wrong here with returning an array of pending Promises before awaiting them all?

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!