Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda