12345678910111213 |
- 'use strict';
- const _ = require('lodash');
- module.exports = options => {
- return async function turnResponse(ctx, next) {
- await next();
- const body = ctx.response.body;
- if (!body) return;
- const { errcode, errmsg, ...others } = body;
- const code = errcode === 0 ? 200 : 500;
- const msg = errmsg === 'ok' ? '操作成功' : '操作失败';
- ctx.response.body = { code, msg, ...others };
- };
- };
|