mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-24 18:36:10 +08:00
fix: request cache 异常
This commit is contained in:
parent
5d10a95941
commit
5c6a7ef788
@ -124,6 +124,7 @@ function createContext(userConfig) {
|
|||||||
|
|
||||||
function getResponseCode(response) {
|
function getResponseCode(response) {
|
||||||
if (response) {
|
if (response) {
|
||||||
|
if (response._rawData) return response._rawData.code;
|
||||||
if (response.data) return response.data.code;
|
if (response.data) return response.data.code;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -180,7 +181,7 @@ export const request = (url, data, options = {}) => {
|
|||||||
|
|
||||||
return currentRequestInstance.request(context).then(async () => {
|
return currentRequestInstance.request(context).then(async () => {
|
||||||
if (!context.error) {
|
if (!context.error) {
|
||||||
return context.config.useResonse ? context.response : context.filterData || context.response.data;
|
return context.config.useResonse ? context.response : context.response.data;
|
||||||
}
|
}
|
||||||
await handleRequestError(context);
|
await handleRequestError(context);
|
||||||
return Promise.reject(context.error);
|
return Promise.reject(context.error);
|
||||||
|
@ -3,8 +3,9 @@ import { isObject } from './helpers';
|
|||||||
// FEATURE: 后续支持 a.b.c
|
// FEATURE: 后续支持 a.b.c
|
||||||
export default async (ctx, next) => {
|
export default async (ctx, next) => {
|
||||||
const dataField = ctx.config.dataField ?? ctx.dataField;
|
const dataField = ctx.config.dataField ?? ctx.dataField;
|
||||||
if (ctx.response && isObject(ctx.response.data) && dataField) {
|
if (!ctx.error && ctx.response && isObject(ctx.response.data) && dataField) {
|
||||||
ctx.filterData = ctx.response.data[dataField];
|
ctx.response._rawData = ctx.response.data;
|
||||||
|
ctx.response.data = ctx.response.data[dataField];
|
||||||
}
|
}
|
||||||
await next();
|
await next();
|
||||||
};
|
};
|
||||||
|
@ -26,10 +26,10 @@ export default {
|
|||||||
// }).then((res) => {
|
// }).then((res) => {
|
||||||
// console.log(res);
|
// console.log(res);
|
||||||
// });
|
// });
|
||||||
request('/api', null, {
|
// request('/api', null, {
|
||||||
}).then((res) => {
|
// }).then((res) => {
|
||||||
console.log(res);
|
// console.log(res);
|
||||||
});
|
// });
|
||||||
// request('/api', null, {
|
// request('/api', null, {
|
||||||
// mergeRequest: true
|
// mergeRequest: true
|
||||||
// }).then((res) => {
|
// }).then((res) => {
|
||||||
@ -71,21 +71,21 @@ export default {
|
|||||||
// });
|
// });
|
||||||
// }, 3200);
|
// }, 3200);
|
||||||
|
|
||||||
// request('/api', null, {
|
request('/api', null, {
|
||||||
// cache: true
|
cache: true
|
||||||
// }).then((res) => {
|
}).then((res) => {
|
||||||
// console.log(res);
|
console.log(res);
|
||||||
// });
|
});
|
||||||
// request('/api', null, {
|
request('/api', null, {
|
||||||
// cache: true
|
cache: true
|
||||||
// }).then((res) => {
|
}).then((res) => {
|
||||||
// console.log(res);
|
console.log(res);
|
||||||
// });
|
});
|
||||||
// request('/api', null, {
|
request('/api', null, {
|
||||||
// cache: true
|
cache: true
|
||||||
// }).then((res) => {
|
}).then((res) => {
|
||||||
// console.log(res);
|
console.log(res);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// request('/api', null, {
|
// request('/api', null, {
|
||||||
// // skipErrorHandler: [500]
|
// // skipErrorHandler: [500]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user