Skip to content

Commit 087bae9

Browse files
mcollinatargos
authored andcommitted
doc: add try/catch in http2 respondWithFile example
PR-URL: #38410 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 8bbaab0 commit 087bae9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

doc/api/http2.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -1636,10 +1636,17 @@ server.on('stream', (stream) => {
16361636
}
16371637

16381638
function onError(err) {
1639-
if (err.code === 'ENOENT') {
1640-
stream.respond({ ':status': 404 });
1641-
} else {
1642-
stream.respond({ ':status': 500 });
1639+
// stream.respond() can throw if the stream has been destroyed by
1640+
// the other side.
1641+
try {
1642+
if (err.code === 'ENOENT') {
1643+
stream.respond({ ':status': 404 });
1644+
} else {
1645+
stream.respond({ ':status': 500 });
1646+
}
1647+
} catch (err) {
1648+
// Perform actual error handling.
1649+
console.log(err);
16431650
}
16441651
stream.end();
16451652
}

0 commit comments

Comments
 (0)