0.0.4 • Published 8 years ago

cosmo-koa-errors v0.0.4

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

cosmo-koa-error

Handles application errors in a central place.

Usage

Install

npm install --save cosmo-koa-errors

setup middleware

const koa        = require('koa');

let app = koa();

// HERE: enable error captures
app.use(require('cosmo-koa-errors')());

// ... setups ... 

app.listen(3000);

throw errors in generator

function *() { 
  
  // param input: string
  // error output: 
  // { error: { message: "record not found" } }
  this.throw("record not found");
  
  // param input: object with message key
  // error output: 
  // { error: { message: "record not found" }}
  this.throw({ message: "record not found", otherKey: "blah" });
  
  // param input: object without message key
  // error output:
  // { error: { hello: "world" } }
  this.throw({ hello: "world"} )

  // Custom Error Status Code:
  this.throw('Error Message', 500);
	
}
0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago