|
@@ -3,6 +3,8 @@ import { Middleware, App } from '@midwayjs/decorator';
|
|
import { NextFunction, Context, Application } from '@midwayjs/koa';
|
|
import { NextFunction, Context, Application } from '@midwayjs/koa';
|
|
import { VOBase } from '../interface/VOBase';
|
|
import { VOBase } from '../interface/VOBase';
|
|
import { get } from 'lodash';
|
|
import { get } from 'lodash';
|
|
|
|
+import { ErrorVO } from '../interface/ErrorVO';
|
|
|
|
+import { ServiceError } from '../error/service.error';
|
|
/**
|
|
/**
|
|
* 返回结果处理拦截器
|
|
* 返回结果处理拦截器
|
|
* 响应头的content-type含有'/files'的情况为请求文件,重写响应头即可
|
|
* 响应头的content-type含有'/files'的情况为请求文件,重写响应头即可
|
|
@@ -24,6 +26,10 @@ export class ResponseMiddleware implements IMiddleware<Context, NextFunction> {
|
|
const resHeaderContentType = response.header['content-type'] as string;
|
|
const resHeaderContentType = response.header['content-type'] as string;
|
|
if (!resHeaderContentType.includes('/files')) {
|
|
if (!resHeaderContentType.includes('/files')) {
|
|
const body = response.body;
|
|
const body = response.body;
|
|
|
|
+ if (body instanceof ServiceError) {
|
|
|
|
+ const r = new ErrorVO(body);
|
|
|
|
+ return r;
|
|
|
|
+ }
|
|
const nb = new VOBase(body as object);
|
|
const nb = new VOBase(body as object);
|
|
return nb;
|
|
return nb;
|
|
} else {
|
|
} else {
|