etherreq 1.0.35 → 1.0.36
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/etherreq.js +11 -2
package/package.json
CHANGED
package/src/etherreq.js
CHANGED
|
@@ -21,6 +21,9 @@ const dispatchRequest = async (config) => {
|
|
|
21
21
|
let response;
|
|
22
22
|
|
|
23
23
|
const { url, method = 'GET', headers = {}, body } = config;
|
|
24
|
+
|
|
25
|
+
let text = ''; // ✅ 提前定义 text 变量
|
|
26
|
+
|
|
24
27
|
try {
|
|
25
28
|
const options = {
|
|
26
29
|
method,
|
|
@@ -31,7 +34,7 @@ const dispatchRequest = async (config) => {
|
|
|
31
34
|
const res = await fetch(url, options);
|
|
32
35
|
|
|
33
36
|
// 先读取文本判断是否是 HTML
|
|
34
|
-
|
|
37
|
+
text = await res.text(); // ✅ 赋值给外部定义的 text
|
|
35
38
|
|
|
36
39
|
if (!res.ok) {
|
|
37
40
|
throw new Error(`HTTP 错误: ${res.status} - ${res.statusText}`);
|
|
@@ -52,6 +55,13 @@ const dispatchRequest = async (config) => {
|
|
|
52
55
|
config,
|
|
53
56
|
};
|
|
54
57
|
} catch (error) {
|
|
58
|
+
error.message += `\n请求地址: ${url}`;
|
|
59
|
+
|
|
60
|
+
// ✅ 安全地添加 text 信息(如果存在)
|
|
61
|
+
if (text) {
|
|
62
|
+
error.message += `\n响应内容: ${text.substring(0, 200)}...`;
|
|
63
|
+
}
|
|
64
|
+
|
|
55
65
|
for (const interceptor of interceptors.response) {
|
|
56
66
|
if (interceptor.rejected) {
|
|
57
67
|
return interceptor.rejected(error);
|
|
@@ -68,7 +78,6 @@ const dispatchRequest = async (config) => {
|
|
|
68
78
|
|
|
69
79
|
return response;
|
|
70
80
|
};
|
|
71
|
-
|
|
72
81
|
const instance = (config) => {
|
|
73
82
|
return dispatchRequest({
|
|
74
83
|
...defaultConfig,
|