etherreq 1.0.4 → 1.0.5

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/myaxios.js +13 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "etherreq",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
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/myaxios.js CHANGED
@@ -30,6 +30,18 @@ export const create = (defaultConfig = {}) => {
30
30
  const res = await fetch(url, options);
31
31
  const data = await res.json();
32
32
 
33
+ // 手动处理 HTTP 错误状态
34
+ if (!res.ok) {
35
+ const error = new Error(`HTTP 错误: ${res.status} - ${res.statusText}`);
36
+ error.response = {
37
+ data,
38
+ status: res.status,
39
+ statusText: res.statusText,
40
+ headers: res.headers,
41
+ };
42
+ throw error;
43
+ }
44
+
33
45
  response = {
34
46
  data,
35
47
  status: res.status,
@@ -71,5 +83,6 @@ export const create = (defaultConfig = {}) => {
71
83
  },
72
84
  };
73
85
 
86
+
74
87
  return instance;
75
88
  };