etherreq 1.0.13 → 1.0.15

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "etherreq",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
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/etherreq.js CHANGED
@@ -19,7 +19,6 @@ export const create = (defaultConfig = {}) => {
19
19
  let response;
20
20
  try {
21
21
  const { url, method = 'GET', headers = {}, body } = config;
22
-
23
22
  const options = {
24
23
  method,
25
24
  headers,
@@ -27,18 +26,7 @@ export const create = (defaultConfig = {}) => {
27
26
  };
28
27
 
29
28
  const res = await fetch(url, options);
30
-
31
- // 判断是否为 JSON 格式响应
32
- const contentType = res.headers.get('content-type');
33
- let data;
34
-
35
- if (contentType && contentType.includes('application/json')) {
36
- data = await res.json(); // 只有 JSON 内容才尝试解析
37
- } else {
38
- data = await res.text(); // 保存原始文本避免报错
39
- throw new Error('非 JSON 响应,可能已跳转至登录页');
40
- }
41
-
29
+ const data = await res.json();
42
30
  if (!res.ok) {
43
31
  const error = new Error(`HTTP 错误: ${res.status} - ${res.statusText}`);
44
32
  error.response = {
package/src/request.js CHANGED
@@ -8,7 +8,6 @@ const instance = create({
8
8
  });
9
9
 
10
10
  // 请求拦截器:自动注入 token、Content-Type 和缓存处理
11
- // src/request.js - 请求拦截器部分
12
11
  instance.interceptors.request.use((config) => {
13
12
  const token = localStorage.getItem('token');
14
13
 
@@ -22,6 +21,8 @@ instance.interceptors.request.use((config) => {
22
21
  if (config.method === 'GET' && !config.disableCache) {
23
22
  const cacheKey = getCacheKey(config.url, config);
24
23
  const cached = requestCache.get(cacheKey);
24
+ console.log('缓存命中:', cacheKey);
25
+ console.log("缓存数据:",cached);
25
26
 
26
27
  if (cached) {
27
28
  // ✅ 返回缓存的 data 数据,中断后续请求流程