@clonegod/ttd-sol-common 2.0.29 → 2.0.31
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.
|
@@ -18,7 +18,7 @@ class HttpClientManager {
|
|
|
18
18
|
maxFreeSockets: 10,
|
|
19
19
|
timeout: 30000,
|
|
20
20
|
});
|
|
21
|
-
|
|
21
|
+
const instance = axios_1.default.create({
|
|
22
22
|
baseURL,
|
|
23
23
|
httpsAgent,
|
|
24
24
|
timeout: 30000,
|
|
@@ -26,6 +26,7 @@ class HttpClientManager {
|
|
|
26
26
|
'Content-Type': 'application/json',
|
|
27
27
|
},
|
|
28
28
|
});
|
|
29
|
+
return instance;
|
|
29
30
|
}
|
|
30
31
|
getInstance(url) {
|
|
31
32
|
const baseURL = url.split('?')[0];
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import axios, { AxiosInstance } from "axios"
|
|
1
|
+
import axios, { AxiosInstance, AxiosError } from "axios"
|
|
2
2
|
import https from "https"
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -22,7 +22,7 @@ class HttpClientManager {
|
|
|
22
22
|
timeout: 30000, // 连接超时
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const instance = axios.create({
|
|
26
26
|
baseURL,
|
|
27
27
|
httpsAgent,
|
|
28
28
|
timeout: 30000,
|
|
@@ -30,6 +30,75 @@ class HttpClientManager {
|
|
|
30
30
|
'Content-Type': 'application/json',
|
|
31
31
|
},
|
|
32
32
|
})
|
|
33
|
+
|
|
34
|
+
// 添加响应拦截器,简化错误信息
|
|
35
|
+
// instance.interceptors.response.use(
|
|
36
|
+
// (response) => response,
|
|
37
|
+
// (error: AxiosError) => {
|
|
38
|
+
// // 简化错误对象,只保留关键信息,避免打印过多内容
|
|
39
|
+
// if (error.response) {
|
|
40
|
+
// // 创建简化的错误对象
|
|
41
|
+
// const simplifiedError = Object.create(AxiosError.prototype)
|
|
42
|
+
// simplifiedError.name = error.name
|
|
43
|
+
// simplifiedError.message = `Request failed: ${error.response.status} ${error.response.statusText} - ${error.config?.method?.toUpperCase()} ${error.config?.url}`
|
|
44
|
+
// simplifiedError.code = error.code
|
|
45
|
+
// simplifiedError.isAxiosError = true
|
|
46
|
+
|
|
47
|
+
// // 只保留必要的配置信息
|
|
48
|
+
// simplifiedError.config = {
|
|
49
|
+
// method: error.config?.method,
|
|
50
|
+
// url: error.config?.url,
|
|
51
|
+
// baseURL: error.config?.baseURL,
|
|
52
|
+
// }
|
|
53
|
+
|
|
54
|
+
// // 只保留必要的响应信息
|
|
55
|
+
// simplifiedError.response = {
|
|
56
|
+
// status: error.response.status,
|
|
57
|
+
// statusText: error.response.statusText,
|
|
58
|
+
// data: error.response.data,
|
|
59
|
+
// }
|
|
60
|
+
|
|
61
|
+
// // 自定义 toJSON 方法,控制序列化输出
|
|
62
|
+
// simplifiedError.toJSON = function() {
|
|
63
|
+
// return {
|
|
64
|
+
// name: this.name,
|
|
65
|
+
// message: this.message,
|
|
66
|
+
// code: this.code,
|
|
67
|
+
// config: this.config,
|
|
68
|
+
// response: this.response,
|
|
69
|
+
// }
|
|
70
|
+
// }
|
|
71
|
+
|
|
72
|
+
// return Promise.reject(simplifiedError as AxiosError)
|
|
73
|
+
// }
|
|
74
|
+
|
|
75
|
+
// // 网络错误等其他错误,简化处理
|
|
76
|
+
// const simplifiedError = Object.create(AxiosError.prototype)
|
|
77
|
+
// simplifiedError.name = error.name
|
|
78
|
+
// simplifiedError.message = `Request error: ${error.message} - ${error.config?.method?.toUpperCase()} ${error.config?.url}`
|
|
79
|
+
// simplifiedError.code = error.code
|
|
80
|
+
// simplifiedError.isAxiosError = true
|
|
81
|
+
// simplifiedError.config = {
|
|
82
|
+
// method: error.config?.method,
|
|
83
|
+
// url: error.config?.url,
|
|
84
|
+
// baseURL: error.config?.baseURL,
|
|
85
|
+
// }
|
|
86
|
+
|
|
87
|
+
// // 自定义 toJSON 方法,控制序列化输出
|
|
88
|
+
// simplifiedError.toJSON = function() {
|
|
89
|
+
// return {
|
|
90
|
+
// name: this.name,
|
|
91
|
+
// message: this.message,
|
|
92
|
+
// code: this.code,
|
|
93
|
+
// config: this.config,
|
|
94
|
+
// }
|
|
95
|
+
// }
|
|
96
|
+
|
|
97
|
+
// return Promise.reject(simplifiedError as AxiosError)
|
|
98
|
+
// }
|
|
99
|
+
// )
|
|
100
|
+
|
|
101
|
+
return instance
|
|
33
102
|
}
|
|
34
103
|
|
|
35
104
|
/**
|