export default (ctx, next) => {
return next().catch((err) => {
if (401 == err.status) {
ctx.status = 401;
ctx.body = {
code: 401,
msg: 'Protected resource, use Authorization header to get access\n'
}
} else {
ctx.status = err.status || 500
ctx.body = Object.assign({
code: 500,
msg: err.message
}, process.env.NODE_ENV === 'development' ? { stack: err.stack } : {})
}
});
}
koa errorHandle统一错误处理
最新推荐文章于 2022-07-17 12:25:54 发布