回调错误处理
🌐 Callback error handling
所有会话和流回调可以是同步函数或异步函数。如果回调同步抛出错误或返回被拒绝的 Promise,该错误将被捕获,并且拥有该回调的会话或流将因该错误而被销毁:
🌐 All session and stream callbacks may be synchronous functions or async functions. If a callback throws synchronously or returns a promise that rejects, the error is caught and the owning session or stream is destroyed with that error:
- 流回调(
onblocked、onreset、onheaders、ontrailers、oninfo、onwanttrailers):流已被销毁。 - 会话回调(
onstream、ondatagram、ondatagramstatus、onpathvalidation、onsessionticket、onnewtoken、onversionnegotiation、onorigin、ongoaway、onhandshake、onkeylog、onqlog):会话会被销毁,同时其所有流也会被销毁。
在销毁之前,将调用可选的 session.onerror 或 stream.onerror 回调(如果已设置),让应用有机会观察或记录错误。session.closed 或 stream.closed 的 promise 将因该错误而被拒绝。
🌐 Before destruction, the optional session.onerror or
stream.onerror callback is invoked (if set), giving the application a
chance to observe or log the error. The session.closed or stream.closed
promise will reject with the error.
如果 onerror 回调本身抛出异常或返回一个被拒绝的 Promise,onerror 的错误将作为未捕获的异常出现。
🌐 If the onerror callback itself throws or returns a promise that rejects,
the error from onerror is surfaced as an uncaught exception.