Skip to content

Commit c5863aa

Browse files
committed
doc: add try/catch in http2 respondWithFile example
1 parent ee9e2a2 commit c5863aa

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

doc/api/http2.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -1669,10 +1669,16 @@ 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+
console.log(err)
16761682
}
16771683
stream.end();
16781684
}

0 commit comments

Comments
 (0)