错误处理


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

当传入不正确的参数、选项或设置值时,则会发生验证错误。 这些将始终由同步 throw 报告。

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

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

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

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

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

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.

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.

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.