From e21938a13633ff9422a42b4240a3f4b1fcb5d6b6 Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Tue, 27 Aug 2013 20:56:17 -0700 Subject: [PATCH] docs --- docs/api.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/api.md b/docs/api.md index d847542..df0f94f 100644 --- a/docs/api.md +++ b/docs/api.md @@ -513,6 +513,26 @@ switch (this.accepts('json', 'html', 'text')) { Request socket object. +### ctx.error(msg, [status]) + + Helper method to throw an error with a `.status` property + that will allow Koa to respond appropriately. The following + combinations are allowed: + +```js +this.error(403) +this.error('name required', 400) +this.error('something exploded') +``` + + For example `this.error('name required', 400)` is requivalent to: + +```js +var err = new Error('name required'); +err.status = 400; +throw err; +``` + ## 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