add socket error handling docs

This commit is contained in:
TJ Holowaychuk 2013-09-08 12:02:59 -07:00
parent 92b741ac0a
commit 28b5b85860

View file

@ -534,7 +534,7 @@ err.status = 400;
throw err;
```
## Error handling
## Error Handling
By default outputs all errors to stderr unless __NODE_ENV__ is "test". To perform custom error-handling logic such as centralized logging you
can add an "error" event listener:
@ -559,7 +559,7 @@ app.on('error', function(err){
## Notes
### HEAD support
### HEAD Support
Koa's upstream response middleware supports __HEAD__ for you,
however expensive requests would benefit from custom handling. For
@ -567,6 +567,20 @@ app.on('error', function(err){
client, you may wish to `stat()` and set the `Content-*` header fields
appropriately to bypass the read.
### Socket Errors
Node http servers emit a "clientError" event when a socket error occurs. You'll probably want to delegate this to your
Koa handler by doing the following, in order to centralize
logging:
```js
var app = koa();
var srv = app.listen(3000);
srv.on('clientError', function(err){
app.emit('error', err);
});
```
# License
MIT