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);
}
};