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

237
Visualizações
How to catch/handle emitted errors within a series of pipes in nodejs?

I need to perform a series of transformations from a source of data. In the event that an error is emitted while data is being sent through the pipeline, I need to handle the error appropriately. Instead the response just hangs.

The only way I can close the hanging response is by calling outStream.close(<string message here>), but that isn't much use because I would like to actually catch the error being emitted.

const seriesOfPipes = async () => {
  try {
      const streams = [transformStream1, transformStream2, transformStream3];
  
      const res = await fetch("foo");
      let outStream = res.body;
  
      for (const streamItem of streams) {
          outStream.on('error', streamItem.destroy.bind(streamItem));
          outStream = outStream.pipe(streamItem);
      }
      return outStream;
  } catch (e) {
      // the error doesn't appear
      console.log("you caught the error ", e.message);
  }
};

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