Skip to content

Commit f197012

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 47626c5 commit f197012

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
@@ -1669,10 +1669,17 @@ server.on('stream', (stream) => {
16691669
}
16701670

16711671
function onError(err) {
1672-
if (err.code === 'ENOENT') {
1673-
stream.respond({ ':status': 404 });
1674-
} else {
1675-
stream.respond({ ':status': 500 });
1672+
// stream.respond() can throw if the stream has been destroyed by
1673+
// the other side.
1674+
try {
1675+
if (err.code === 'ENOENT') {
1676+
stream.respond({ ':status': 404 });
1677+
} else {
1678+
stream.respond({ ':status': 500 });
1679+
}
1680+
} catch (err) {
1681+
// Perform actual error handling.
1682+
console.log(err);
16761683
}
16771684
stream.end();
16781685
}

0 commit comments

Comments
 (0)