add socket error handling docs
This commit is contained in:
parent
92b741ac0a
commit
28b5b85860
1 changed files with 16 additions and 2 deletions
18
docs/api.md
18
docs/api.md
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue