2022-03-23 11:36:38 +08:00

22 lines
534 B
JavaScript

import { isObject } from './helpers';
// 错误处理等副作用网上提
export default async (ctx, next) => {
const {
response,
config
} = ctx;
if (!config.closeResDataCheck && response && isObject(response.data)) {
const code = response.data.code;
if (code !== '0') {
// 尽量保持内部 error 结构和 http 异常的 error 结构一致
ctx.error = {
...response,
response
};
}
}
await next();
};