diff --git a/doc/api/http2.md b/doc/api/http2.md index 623e6a96071cb7..fd83a711313c8e 100644 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -1636,10 +1636,17 @@ server.on('stream', (stream) => { } function onError(err) { - if (err.code === 'ENOENT') { - stream.respond({ ':status': 404 }); - } else { - stream.respond({ ':status': 500 }); + // stream.respond() can throw if the stream has been destroyed by + // the other side. + try { + if (err.code === 'ENOENT') { + stream.respond({ ':status': 404 }); + } else { + stream.respond({ ':status': 500 }); + } + } catch (err) { + // Perform actual error handling. + console.log(err); } stream.end(); }