diff --git a/docs/zh/reference/plugin/plugins/request.md b/docs/zh/reference/plugin/plugins/request.md index 777ad34e..b4c557f5 100644 --- a/docs/zh/reference/plugin/plugins/request.md +++ b/docs/zh/reference/plugin/plugins/request.md @@ -51,6 +51,8 @@ export const request = { responseDataAdaptor: (data) => { }, + // 关闭 response data 校验(只判断 xhr status) + closeResDataCheck: false, // 请求拦截器 requestInterceptors: [], // 相应拦截器 diff --git a/packages/fes-plugin-request/src/template/resErrorProcess.js b/packages/fes-plugin-request/src/template/resErrorProcess.js index d0f6db42..370c5511 100644 --- a/packages/fes-plugin-request/src/template/resErrorProcess.js +++ b/packages/fes-plugin-request/src/template/resErrorProcess.js @@ -25,9 +25,10 @@ export default async (ctx, next) => { const { error, errorHandler = {}, - response + response, + config } = ctx; - if (response && isObject(response.data)) { + if (!config.closeResDataCheck && response && isObject(response.data)) { const code = response.data.code; if (code !== '0') { handleAbnormalCode(errorHandler, code, response); diff --git a/packages/fes-template-h5/src/app.js b/packages/fes-template-h5/src/app.js index f5074050..f340fe58 100644 --- a/packages/fes-template-h5/src/app.js +++ b/packages/fes-template-h5/src/app.js @@ -1,4 +1,14 @@ export const request = { + responseInterceptors: [(response) => { + console.log(response); + if (response.data !== '0') { + return Promise.reject({ + response + }); + } + return response; + }], + closeResDataCheck: true, errorHandler: { 111(responseData) { console.log(responseData); @@ -7,7 +17,7 @@ export const request = { console.log('to 404 page'); }, default(error) { - console.log(error.response.data); + console.log(error); } } }; diff --git a/packages/fes-template-h5/src/pages/index.vue b/packages/fes-template-h5/src/pages/index.vue index 29e5530c..b412e89b 100644 --- a/packages/fes-template-h5/src/pages/index.vue +++ b/packages/fes-template-h5/src/pages/index.vue @@ -2,8 +2,6 @@
fes & 拉夫德鲁
-
loading
-
{{data}}
@@ -14,7 +12,7 @@