错误处理


【Error handling】

使用 node:http2 模块时,可能会出现几种类型的错误情况:

【There are several types of error conditions that may arise when using the node:http2 module:】

当传入不正确的参数、选项或设置值时,会发生验证错误。这些错误总是通过同步 throw 报告。

【Validation errors occur when an incorrect argument, option, or setting value is passed in. These will always be reported by a synchronous throw.】

状态错误发生在尝试在不正确的时间执行某个操作时(例如,在流关闭后尝试发送数据)。这些错误将通过同步的 throw 或在 Http2StreamHttp2Session 或 HTTP/2 服务器对象上触发的 'error' 事件来报告,具体取决于错误发生的地点和时间。

【State errors occur when an action is attempted at an incorrect time (for instance, attempting to send data on a stream after it has closed). These will be reported using either a synchronous throw or via an 'error' event on the Http2Stream, Http2Session or HTTP/2 Server objects, depending on where and when the error occurs.】

当 HTTP/2 会话意外失败时,会发生内部错误。这些错误将通过 Http2Session 或 HTTP/2 服务器对象上的 'error' 事件报告。

【Internal errors occur when an HTTP/2 session fails unexpectedly. These will be reported via an 'error' event on the Http2Session or HTTP/2 Server objects.】

当违反各种 HTTP/2 协议约束时,会发生协议错误。
这些错误会通过同步 throw 抛出,或者在 Http2StreamHttp2Session 或 HTTP/2 服务器对象上通过 'error' 事件报告,具体取决于错误发生的地点和时间。

【Protocol errors occur when various HTTP/2 protocol constraints are violated. These will be reported using either a synchronous throw or via an 'error' event on the Http2Stream, Http2Session or HTTP/2 Server objects, depending on where and when the error occurs.】