错误处理


🌐 Error handling

quic 模块中的错误通过两种互补机制进行传递:onerror 回调和 closed Promise。

🌐 Errors in the quic module are communicated through two complementary mechanisms: the onerror callback and the closed promise.

QuicSessionQuicStream 都提供一个可选的 onerror 回调。 当会话或流因错误被销毁时 —— 包括其他用户回调抛出的错误 —— onerror 回调会在对象被销毁之前用该错误被调用。设置 onerror 也会将 closed Promise 标记为已处理,从而防止未处理拒绝警告。如果未设置 onerror,错误将仅通过 closed Promise 的拒绝传递。

🌐 Both QuicSession and QuicStream expose an optional onerror callback. When a session or stream is destroyed with an error — including errors thrown by other user callbacks — the onerror callback is invoked with the error before the object is torn down. Setting onerror also marks the closed promise as handled, preventing unhandled rejection warnings. If onerror is not set, the error is delivered solely through the rejection of the closed promise.

QuicError 类携带一个明确的数字 QUIC 错误代码 (error.errorCode),以及通常的 messagecode 属性。当 QuicError 被传递给 stream.destroy()writer.fail() 时,其 errorCode 会被用于发送给对端的 RESET_STREAMSTOP_SENDING 帧中。任何其他错误类型都会回退到协商协议的通用内部错误代码。

🌐 The QuicError class carries an explicit numeric QUIC error code (error.errorCode) alongside the usual message and code properties. When a QuicError is passed to stream.destroy() or writer.fail(), its errorCode is used in the RESET_STREAM or STOP_SENDING frame sent to the peer. Any other error type falls back to the negotiated protocol's generic internal error code.