1234567891011121314151617181920 |
- 'use strict';
- module.exports = () => {
- return async function errorHandler(ctx, next) {
- try {
- await next();
- } catch (err) {
- console.log(err);
- if (err.status === 401) {
- ctx.body = { errcode: err.status, errmsg: '请登录' };
- ctx.status = err.status;
- return false;
- }
- const { message } = err;
- const json = JSON.parse(message);
- ctx.logger.error(json.error);
- ctx.body = json;
- ctx.status = 400;
- }
- };
- };
|