Skip to content

Commit

Permalink
doc: add try/catch in http2 respondWithFile example
Browse files Browse the repository at this point in the history
PR-URL: #38410
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
mcollina authored and targos committed Jun 11, 2021
1 parent 378e0e7 commit 945450b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions doc/api/http2.md
Expand Up @@ -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();
}
Expand Down

0 comments on commit 945450b

Please sign in to comment.