Skip to content

Instantly share code, notes, and snippets.

@kazu69
Created March 12, 2014 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazu69/9501131 to your computer and use it in GitHub Desktop.
Save kazu69/9501131 to your computer and use it in GitHub Desktop.
koa.js error handling sample
var koa = require('koa');
var app = koa();
app.use(function *(next){
try {
yield next;
}
catch (err) {
console.log(err);
this.status = err.status || 500;
this.body = err.message || require('http').STATUS_CODES[this.status];
}
});
app.use(function *(next){
throw new Error('some error');
});
app.listen(3000);
node --harmony error.js
[Error: some error]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment