doc: add note about clientError writable handling

PR-URL: https://github.com/nodejs/node/pull/33308
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
pull/33375/head
Paolo Insogna 2020-05-08 12:27:52 +02:00 committed by Matteo Collina
parent 0ddae48b88
commit 5bb4d01fbe
1 changed files with 15 additions and 0 deletions

View File

@ -1045,6 +1045,21 @@ ensure the response is a properly formatted HTTP response message.
correctly;
* `rawPacket`: the raw packet of current request.
In some cases, the client has already received the response and/or the socket
has already been destroyed, like in case of `ECONNRESET` errors. Before
trying to send data to the socket, it is better to check that it is still
writable.
```js
server.on('clientError', (err, socket) => {
if (err.code === 'ECONNRESET' || !socket.writable) {
return;
}
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n');
});
```
### Event: `'close'`
<!-- YAML
added: v0.1.4