12345678910111213141516171819 |
- 'use strict';
- module.exports = () => {
- return async function errorHandler(ctx, next) {
- try {
- await next();
- } catch (err) {
- const { message } = err;
- let json = {
- errcode: -1001,
- errmsg: message,
- };
- if (err.code !== 'ERR_ASSERTION') {
- json = JSON.parse(message);
- }
- ctx.body = json;
- ctx.status = 400;
- }
- };
- };
|