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

236
Views
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
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!