@clonegod/ttd-sol-common 2.0.29 → 2.0.30
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.
|
@@ -1,10 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
39
|
exports.getHttpClient = getHttpClient;
|
|
7
|
-
const axios_1 =
|
|
40
|
+
const axios_1 = __importStar(require("axios"));
|
|
8
41
|
const https_1 = __importDefault(require("https"));
|
|
9
42
|
class HttpClientManager {
|
|
10
43
|
constructor() {
|
|
@@ -18,7 +51,7 @@ class HttpClientManager {
|
|
|
18
51
|
maxFreeSockets: 10,
|
|
19
52
|
timeout: 30000,
|
|
20
53
|
});
|
|
21
|
-
|
|
54
|
+
const instance = axios_1.default.create({
|
|
22
55
|
baseURL,
|
|
23
56
|
httpsAgent,
|
|
24
57
|
timeout: 30000,
|
|
@@ -26,6 +59,56 @@ class HttpClientManager {
|
|
|
26
59
|
'Content-Type': 'application/json',
|
|
27
60
|
},
|
|
28
61
|
});
|
|
62
|
+
instance.interceptors.response.use((response) => response, (error) => {
|
|
63
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
64
|
+
if (error.response) {
|
|
65
|
+
const simplifiedError = Object.create(axios_1.AxiosError.prototype);
|
|
66
|
+
simplifiedError.name = error.name;
|
|
67
|
+
simplifiedError.message = `Request failed: ${error.response.status} ${error.response.statusText} - ${(_b = (_a = error.config) === null || _a === void 0 ? void 0 : _a.method) === null || _b === void 0 ? void 0 : _b.toUpperCase()} ${(_c = error.config) === null || _c === void 0 ? void 0 : _c.url}`;
|
|
68
|
+
simplifiedError.code = error.code;
|
|
69
|
+
simplifiedError.isAxiosError = true;
|
|
70
|
+
simplifiedError.config = {
|
|
71
|
+
method: (_d = error.config) === null || _d === void 0 ? void 0 : _d.method,
|
|
72
|
+
url: (_e = error.config) === null || _e === void 0 ? void 0 : _e.url,
|
|
73
|
+
baseURL: (_f = error.config) === null || _f === void 0 ? void 0 : _f.baseURL,
|
|
74
|
+
};
|
|
75
|
+
simplifiedError.response = {
|
|
76
|
+
status: error.response.status,
|
|
77
|
+
statusText: error.response.statusText,
|
|
78
|
+
data: error.response.data,
|
|
79
|
+
};
|
|
80
|
+
simplifiedError.toJSON = function () {
|
|
81
|
+
return {
|
|
82
|
+
name: this.name,
|
|
83
|
+
message: this.message,
|
|
84
|
+
code: this.code,
|
|
85
|
+
config: this.config,
|
|
86
|
+
response: this.response,
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
return Promise.reject(simplifiedError);
|
|
90
|
+
}
|
|
91
|
+
const simplifiedError = Object.create(axios_1.AxiosError.prototype);
|
|
92
|
+
simplifiedError.name = error.name;
|
|
93
|
+
simplifiedError.message = `Request error: ${error.message} - ${(_h = (_g = error.config) === null || _g === void 0 ? void 0 : _g.method) === null || _h === void 0 ? void 0 : _h.toUpperCase()} ${(_j = error.config) === null || _j === void 0 ? void 0 : _j.url}`;
|
|
94
|
+
simplifiedError.code = error.code;
|
|
95
|
+
simplifiedError.isAxiosError = true;
|
|
96
|
+
simplifiedError.config = {
|
|
97
|
+
method: (_k = error.config) === null || _k === void 0 ? void 0 : _k.method,
|
|
98
|
+
url: (_l = error.config) === null || _l === void 0 ? void 0 : _l.url,
|
|
99
|
+
baseURL: (_m = error.config) === null || _m === void 0 ? void 0 : _m.baseURL,
|
|
100
|
+
};
|
|
101
|
+
simplifiedError.toJSON = function () {
|
|
102
|
+
return {
|
|
103
|
+
name: this.name,
|
|
104
|
+
message: this.message,
|
|
105
|
+
code: this.code,
|
|
106
|
+
config: this.config,
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
return Promise.reject(simplifiedError);
|
|
110
|
+
});
|
|
111
|
+
return instance;
|
|
29
112
|
}
|
|
30
113
|
getInstance(url) {
|
|
31
114
|
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
|
/**
|