Created
March 12, 2014 04:59
-
-
Save kazu69/9501131 to your computer and use it in GitHub Desktop.
koa.js error handling sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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