docs: update docs:

This commit is contained in:
winixt 2023-12-27 17:51:02 +08:00
parent 9c5283aef0
commit a5cde50a22

View File

@ -23,24 +23,28 @@
```js ```js
import { defineRuntimeConfig } from '@fesjs/fes'; import { defineRuntimeConfig } from '@fesjs/fes';
import { isPlainObject } from 'lodash-es';
export default defineRuntimeConfig({ export default defineRuntimeConfig({
request: { request: {
// API 前缀 // API 前缀
baseURL: '', baseURL: '',
dataHandler(data, response) { dataHandler(data, response) {
// 处理响应内容异常 if (isPlainObject(data)) {
if (data.code !== '0') { // 处理响应内容异常
if (data.code === '10000') if (data.code !== '0') {
FMesseage.error('hello world'); if (data.code === '10000')
FMesseage.error('hello world');
if (data.code === '20000') if (data.code === '20000')
FMesseage.error('hello world'); FMesseage.error('hello world');
throw new Error(response); throw new Error(response);
}
// 响应数据格式化
return data?.result ? data.result : data;
} }
// 响应数据格式化 return data;
return data?.result ? data.result : data;
}, },
// http 异常,和插件异常 // http 异常,和插件异常
errorHandler(error) { errorHandler(error) {