From 098d175ddfef052f8e676205c23f4a87dd6d2e7b Mon Sep 17 00:00:00 2001 From: winixt Date: Wed, 27 Dec 2023 17:51:02 +0800 Subject: [PATCH] docs: update docs: --- docs/reference/plugin/plugins/request.md | 26 ++++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/docs/reference/plugin/plugins/request.md b/docs/reference/plugin/plugins/request.md index 7dfd20daa..09270d420 100644 --- a/docs/reference/plugin/plugins/request.md +++ b/docs/reference/plugin/plugins/request.md @@ -23,24 +23,28 @@ ```js import { defineRuntimeConfig } from '@fesjs/fes'; +import { isPlainObject } from 'lodash-es'; export default defineRuntimeConfig({ request: { // API 前缀 baseURL: '', dataHandler(data, response) { - // 处理响应内容异常 - if (data.code !== '0') { - if (data.code === '10000') - FMesseage.error('hello world'); - - if (data.code === '20000') - FMesseage.error('hello world'); - - throw new Error(response); + if (isPlainObject(data)) { + // 处理响应内容异常 + if (data.code !== '0') { + if (data.code === '10000') + FMesseage.error('hello world'); + + if (data.code === '20000') + FMesseage.error('hello world'); + + throw new Error(response); + } + // 响应数据格式化 + return data?.result ? data.result : data; } - // 响应数据格式化 - return data?.result ? data.result : data; + return data; }, // http 异常,和插件异常 errorHandler(error) {