1 | /**
|
2 | * Created by liuzhengdong on 2018/4/3.
|
3 | * 错误处理中间件
|
4 | * @param {ctx} ctx koa ctx
|
5 | * @param {Function} next koa next */
|
6 |
|
7 | module.exports = async function (ctx, next) {
|
8 | try {
|
9 | // Node标识
|
10 | ctx.set('X-Proxy', 'Node Server')
|
11 | await next()
|
12 | } catch (err) {
|
13 | ctx.status = err.status || 500
|
14 | ctx.body = 'We are sorry. Internal server error occurred.'
|
15 | ctx.app.emit('error', err, ctx)
|
16 | }
|
17 | }
|