etherreq 1.1.4 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/request.js +6 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "etherreq",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "A lightweight custom HTTP request library.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/types/etherreq.d.ts",
package/src/request.js CHANGED
@@ -44,19 +44,20 @@ instance.interceptors.request.use((config) => {
44
44
 
45
45
  // 响应拦截器:自动提取 response.data 并写入缓存
46
46
  instance.interceptors.response.use(
47
- (response) => {
48
- // 判断是否是缓存返回的数据(没有 .config)
49
- if (!response.config && response.data !== undefined) {
50
- // 已经是 data,直接返回
51
- return response;
47
+ (response) => {
48
+ // 如果是缓存命中,直接返回 cached 数据
49
+ if (response && response.isFromCache) {
50
+ return response.data; // 返回 cached 数据
52
51
  }
53
52
 
53
+ // 否则正常处理 response.data
54
54
  const config = response.config;
55
55
 
56
56
  if (config && config.method === 'GET' && !config.disableCache) {
57
57
  const cacheKey = getCacheKey(config.url, config);
58
58
  requestCache.set(cacheKey, response.data);
59
59
  }
60
+
60
61
  return response.data;
61
62
  },
62
63
  (error) => {