TransformStreamDefaultController: error() メソッド

Invalid slug for templ/sidebar: Streams API

error()TransformStreamDefaultController インターフェイスのメソッドで、両側のストリームをエラーにします。これ以上何か操作をすると、指定されたエラーメッセージとともに失敗するようになり、キュー内のチャンクは破棄されます。

構文

js
error(reason)

引数

reason

それ以降のストリームの操作において返されるエラーメッセージを格納した文字列。

返値

なし (undefined)。

この例では、チャンクが変換できなかったときに error() メソッドを使用しています。

js
const transformContent = {
  start() {
    /* … */
  },
  async transform(chunk, controller) {
    try {
      chunk = await applyMyTransformation(chunk);
    } catch (err) {
      controller.error(`Unable to transform chunk: ${err}`);
    }
    // …
  },
  // …
};

仕様書

Specification
Streams
# ts-default-controller-error

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
error

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support