From c6c133ca5afacdf9a16e676568915ce92b9f232a Mon Sep 17 00:00:00 2001 From: bac-joker Date: Mon, 26 Apr 2021 17:34:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20request=20=E6=B7=BB=E5=8A=A0=E5=85=B3?= =?UTF-8?q?=E9=97=ADcode=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/reference/plugin/plugins/request.md | 2 ++ .../src/template/resErrorProcess.js | 5 +++-- packages/fes-template-h5/src/app.js | 12 +++++++++++- packages/fes-template-h5/src/pages/index.vue | 12 ++++++------ 4 files changed, 22 insertions(+), 9 deletions(-) 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 @@