The error()
method of the TransformStreamDefaultController
interface errors both sides of the stream. Any further interactions with it will fail with the given error message, and any chunks in the queue will be discarded.
On this page
TransformStreamDefaultController: error() method
Syntax
js
error(reason)
Parameters
-
reason
-
A string containing the error message to be returned on any further interaction with the stream.
Return value
None (undefined
).
Examples
In this example the error()
method is used when a chunk could not be transformed.
js
const transformContent = {
start() {
/* … */
},
async transform(chunk, controller) {
try {
chunk = await applyMyTransformation(chunk);
} catch (err) {
controller.error(`Unable to transform chunk: ${err}`);
}
// …
},
// …
};
Specifications
Specification |
---|
Streams Standard # ts-default-controller-error |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
error |
67 | 79 | 102 | No | 54 | 14.1 | 67 | 67 | 102 | 48 | 14.5 | 9.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/TransformStreamDefaultController/error