Create error middleware

This commit is contained in:
Adrian Obelmejias
2016-02-11 14:51:46 -05:00
parent fe820decc3
commit 04e154e4d8
+11
View File
@@ -0,0 +1,11 @@
export function errorMiddleware() {
return async (ctx, next) => {
try {
await next();
} catch (err) {
ctx.status = err.status || 500
ctx.body = err.message
ctx.app.emit('error', err, ctx)
}
}
}