Skip to content

Commit

Permalink
doc: add try/catch in http2 respondWithFile example
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Apr 26, 2021
1 parent ee9e2a2 commit c5863aa
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions doc/api/http2.md
Expand Up @@ -1669,10 +1669,16 @@ 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) {
console.log(err)
}
stream.end();
}
Expand Down

0 comments on commit c5863aa

Please sign in to comment.