From 28b5b85860abc403fd2bc0c01784853342a52653 Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Sun, 8 Sep 2013 12:02:59 -0700 Subject: [PATCH] add socket error handling docs --- docs/api.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/api.md b/docs/api.md index fc1df72..e6e148b 100644 --- a/docs/api.md +++ b/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