类:QuicError


🌐 Class: QuicError

稳定性: 1 - 实验性

QuicError 是一个 Error 子类,携带一个明确的数字 QUIC 错误码。使用它可以中止 QUIC 流或会话,并带有特定的应用协议定义的错误码,而不是让实现选择通用的回退错误码。

🌐 A QuicError is an Error subclass that carries an explicit numeric QUIC error code. Use it to abort a QUIC stream or session with a specific application-protocol-defined error code rather than letting the implementation pick a generic fallback.

该类从 node:quic 导出:

🌐 The class is exported from node:quic:

import { QuicError } from 'node:quic';const { QuicError } = require('node:quic');

当向发出帧的 API(writer.fail()stream.destroy())提供 QuicError 时,QUIC 堆栈会使用 error.errorCode 作为生成帧的线编码。 当提供任何其他值(例如普通的 Error)时,实现在回退到协商的应用协议的“内部错误”代码(HTTP/3 为 H3_INTERNAL_ERROR (0x102),或原生 QUIC 的 QUIC 传输层 INTERNAL_ERROR (0x1))。

🌐 When a QuicError is supplied to APIs that emit a wire frame (writer.fail(), stream.destroy()), the QUIC stack uses error.errorCode as the wire code for the resulting frame. When any other value is supplied (for example a plain Error), the implementation falls back to the negotiated application protocol's "internal error" code (H3_INTERNAL_ERROR (0x102) for HTTP/3, or the QUIC transport-layer INTERNAL_ERROR (0x1) for raw QUIC).

Node.js 错误代码(error.code)默认是 'ERR_QUIC_STREAM_ABORTED'。需要更具体代码字符串的调用者可以通过 options.code 覆盖它 —— 数字 QUIC 代码不受影响。

🌐 The Node.js error code (error.code) defaults to 'ERR_QUIC_STREAM_ABORTED'. Callers who need a more specific code string can override it via options.code — the numeric QUIC code is unaffected.

Node.js 错误代码固定为 'ERR_QUIC_STREAM_ABORTED',以便 catch 块可以区分 QuicError 与其他 Node.js 错误,而无需检查原型链。数字 QUIC 代码存在于单独的 error.errorCode 属性上,以避免与 Node.js 约定的 error.code 为字符串发生冲突。

🌐 The Node.js error code is fixed at 'ERR_QUIC_STREAM_ABORTED' so that catch blocks can distinguish a QuicError from other Node.js errors without checking the prototype chain. The numeric QUIC code lives on the separate error.errorCode property to avoid colliding with the Node.js convention that error.code is a string.