etherreq 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/request.js +7 -7
package/package.json
CHANGED
package/src/request.js
CHANGED
|
@@ -32,8 +32,7 @@ instance.interceptors.request.use((config) => {
|
|
|
32
32
|
console.log(cached);
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
return Promise.resolve(fakeResponse
|
|
36
|
-
); // ✅ 返回响应对象,中断请求链
|
|
35
|
+
return Promise.resolve(fakeResponse); // ✅ 返回响应对象,中断请求链
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
|
|
@@ -45,19 +44,20 @@ instance.interceptors.request.use((config) => {
|
|
|
45
44
|
|
|
46
45
|
// 响应拦截器:自动提取 response.data 并写入缓存
|
|
47
46
|
instance.interceptors.response.use(
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
if (
|
|
51
|
-
//
|
|
52
|
-
return response;
|
|
47
|
+
(response) => {
|
|
48
|
+
// 如果是缓存命中,直接返回 cached 数据
|
|
49
|
+
if (response && response.isFromCache) {
|
|
50
|
+
return response.data; // ✅ 返回 cached 数据
|
|
53
51
|
}
|
|
54
52
|
|
|
53
|
+
// 否则正常处理 response.data
|
|
55
54
|
const config = response.config;
|
|
56
55
|
|
|
57
56
|
if (config && config.method === 'GET' && !config.disableCache) {
|
|
58
57
|
const cacheKey = getCacheKey(config.url, config);
|
|
59
58
|
requestCache.set(cacheKey, response.data);
|
|
60
59
|
}
|
|
60
|
+
|
|
61
61
|
return response.data;
|
|
62
62
|
},
|
|
63
63
|
(error) => {
|