A JavaScript TransformStream implementation retrieves and emits the events that makes up a stream (stream chunks, stream end and stream error) in the following way:
Event | How to retrieve | How to emit |
---|---|---|
Stream chunk | transform method in TransformStream constructor |
controller.enqueue() |
Stream end | flush method in TransformStream constructor |
controller.terminate() |
Stream error | ??? | controller.error() |
The default behaviour for a TransformStream is to forward each of these events from the input (writable) stream to the output (readable) stream, and this behaviour can be customized by using the methods outlined in the table.
I have a special use case where I would like to cause some side effects when an error is forwarded from the input to the output stream. I can also imagine some use cases where the TransformStream does not want to forward the error at all, but react to it in a different way. However, as you can see in the table, I have not been able to find a way to retrieve the error.
How can I react to a stream error in the input (readable) stream of a TransformStream?