@ekhein/http-request 1.0.6 → 1.0.7
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/dist/exceptions/index.d.ts +2 -2
- package/dist/exceptions/index.js +5 -5
- package/dist/exceptions/retryLimitError.d.ts +4 -0
- package/dist/exceptions/retryLimitError.js +12 -0
- package/dist/exceptions/retryableError.d.ts +4 -0
- package/dist/exceptions/retryableError.js +12 -0
- package/dist/libs/formData.d.ts +3 -0
- package/dist/libs/formData.js +10 -0
- package/dist/libs/index.d.ts +1 -0
- package/dist/libs/index.js +5 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +34 -22
- package/package.json +2 -1
- package/types/http-request.d.ts +4 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { HttpRetryableError } from './retryableError';
|
|
2
|
+
export { HttpRetryLimitError } from './retryLimitError';
|
package/dist/exceptions/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "
|
|
3
|
+
exports.HttpRetryLimitError = exports.HttpRetryableError = void 0;
|
|
4
|
+
var retryableError_1 = require("./retryableError");
|
|
5
|
+
Object.defineProperty(exports, "HttpRetryableError", { enumerable: true, get: function () { return retryableError_1.HttpRetryableError; } });
|
|
6
|
+
var retryLimitError_1 = require("./retryLimitError");
|
|
7
|
+
Object.defineProperty(exports, "HttpRetryLimitError", { enumerable: true, get: function () { return retryLimitError_1.HttpRetryLimitError; } });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpRetryLimitError = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
class HttpRetryLimitError extends axios_1.AxiosError {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
const code = String("AXIOS_RETRY_LIMIT_ERROR");
|
|
8
|
+
const message = String("Axios retry limit error");
|
|
9
|
+
super(message, code, config);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.HttpRetryLimitError = HttpRetryLimitError;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpRetryableError = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
class HttpRetryableError extends axios_1.AxiosError {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
const code = String("AXIOS_RETRYABLE_ERROR");
|
|
8
|
+
const message = String("Axios retryable error");
|
|
9
|
+
super(message, code, config);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.HttpRetryableError = HttpRetryableError;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FormData = void 0;
|
|
7
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
8
|
+
class FormData extends form_data_1.default {
|
|
9
|
+
}
|
|
10
|
+
exports.FormData = FormData;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FormData } from './formData';
|
package/dist/main.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -54,6 +54,7 @@ const cookie_1 = require("cookie");
|
|
|
54
54
|
const tldts_1 = require("tldts");
|
|
55
55
|
const common_1 = require("@nestjs/common");
|
|
56
56
|
const http_error_by_code_util_1 = require("@nestjs/common/utils/http-error-by-code.util");
|
|
57
|
+
const libs_1 = require("./libs");
|
|
57
58
|
const agent_1 = require("./agent");
|
|
58
59
|
const agent_2 = require("./agent");
|
|
59
60
|
const agent_3 = require("./agent");
|
|
@@ -137,8 +138,13 @@ class HttpRequest {
|
|
|
137
138
|
request.data = request.body;
|
|
138
139
|
}
|
|
139
140
|
if (request.form) {
|
|
140
|
-
request.
|
|
141
|
-
|
|
141
|
+
if (request.form instanceof libs_1.FormData) {
|
|
142
|
+
request.data = request.form;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
request.headers.setContentType("application/x-www-form-urlencoded");
|
|
146
|
+
request.data = request.form;
|
|
147
|
+
}
|
|
142
148
|
}
|
|
143
149
|
return request;
|
|
144
150
|
}));
|
|
@@ -161,49 +167,54 @@ class HttpRequest {
|
|
|
161
167
|
request.__origin__ = (0, lodash_1.cloneDeep)(request);
|
|
162
168
|
return (request);
|
|
163
169
|
}));
|
|
170
|
+
/* Call Custom Hook */
|
|
171
|
+
this.instance.interceptors.response.use((_c = options.interceptorHooks) === null || _c === void 0 ? void 0 : _c.respondInterceptor, (_d = options.interceptorHooks) === null || _d === void 0 ? void 0 : _d.respondInterceptorCatch);
|
|
164
172
|
/* Transform */
|
|
165
173
|
this.instance.interceptors.response.use((response) => __awaiter(this, void 0, void 0, function* () {
|
|
166
|
-
if (response.
|
|
167
|
-
if (
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
174
|
+
if (typeof response.headers == "object") {
|
|
175
|
+
if (response.headers instanceof axios_1.AxiosHeaders) {
|
|
176
|
+
if (response.config.serviceType == 1) {
|
|
177
|
+
if (http_error_by_code_util_1.HttpErrorByCode[response.data.err])
|
|
178
|
+
throw new http_error_by_code_util_1.HttpErrorByCode[response.data.err](response.data.msg);
|
|
179
|
+
return response.data.res;
|
|
180
|
+
}
|
|
181
|
+
if (response.config.serviceType == 2) {
|
|
182
|
+
if (response.data.status)
|
|
183
|
+
throw new common_1.ServiceUnavailableException(response.data.message);
|
|
184
|
+
return response.data.data;
|
|
185
|
+
}
|
|
186
|
+
if (response.config.html) {
|
|
187
|
+
return new jsdom_1.JSDOM(response.data);
|
|
188
|
+
}
|
|
189
|
+
if (response.config.resolveBodyOnly != false) {
|
|
190
|
+
return response.data;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
180
193
|
}
|
|
181
194
|
return response;
|
|
182
195
|
}));
|
|
183
|
-
/* Call Custom Hook */
|
|
184
|
-
this.instance.interceptors.response.use((_c = options.interceptorHooks) === null || _c === void 0 ? void 0 : _c.respondInterceptor, (_d = options.interceptorHooks) === null || _d === void 0 ? void 0 : _d.respondInterceptorCatch);
|
|
185
196
|
/* Handler Timeout */
|
|
186
197
|
this.instance.interceptors.response.use((response) => __awaiter(this, void 0, void 0, function* () { return response; }), (error) => __awaiter(this, void 0, void 0, function* () {
|
|
187
198
|
if (error instanceof axios_1.AxiosError) {
|
|
188
199
|
if (!error.code)
|
|
189
|
-
throw new exceptions_1.
|
|
200
|
+
throw new exceptions_1.HttpRetryableError(error.config);
|
|
190
201
|
switch (error.code) {
|
|
191
202
|
case axios_1.AxiosError.ETIMEDOUT:
|
|
192
203
|
case axios_1.AxiosError.ERR_NETWORK:
|
|
193
204
|
case axios_1.AxiosError.ECONNABORTED:
|
|
194
|
-
throw new exceptions_1.
|
|
205
|
+
throw new exceptions_1.HttpRetryableError(error.config);
|
|
195
206
|
}
|
|
196
207
|
}
|
|
197
208
|
throw error;
|
|
198
209
|
}));
|
|
199
210
|
/* Auto Retry */
|
|
200
211
|
this.instance.interceptors.response.use((response) => __awaiter(this, void 0, void 0, function* () { return response; }), (error) => __awaiter(this, void 0, void 0, function* () {
|
|
201
|
-
if (error instanceof exceptions_1.
|
|
212
|
+
if (error instanceof exceptions_1.HttpRetryableError) {
|
|
202
213
|
const retryCount = error.config.__origin__.retryCount++;
|
|
203
214
|
const retryLimit = error.config.__origin__.retryLimit;
|
|
204
215
|
if (retryCount < retryLimit)
|
|
205
216
|
return this.instance.request(error.config.__origin__);
|
|
206
|
-
throw new exceptions_1.
|
|
217
|
+
throw new exceptions_1.HttpRetryLimitError(error.config);
|
|
207
218
|
}
|
|
208
219
|
else {
|
|
209
220
|
throw error;
|
|
@@ -230,4 +241,5 @@ class HttpRequest {
|
|
|
230
241
|
}
|
|
231
242
|
}
|
|
232
243
|
exports.HttpRequest = HttpRequest;
|
|
244
|
+
__exportStar(require("./libs"), exports);
|
|
233
245
|
__exportStar(require("./exceptions"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ekhein/http-request",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "ekhein",
|
|
6
6
|
"main": "./dist/main.js",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"@nestjs/common": "^10.0.0",
|
|
26
26
|
"axios": "^1.12.2",
|
|
27
27
|
"cookie": "^1.0.2",
|
|
28
|
+
"form-data": "^4.0.4",
|
|
28
29
|
"http-cookie-agent": "^7.0.2",
|
|
29
30
|
"jsdom": "^25.0.1",
|
|
30
31
|
"lodash": "^4.17.21",
|
package/types/http-request.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CookieJar } from
|
|
1
|
+
import { JSDOM } from 'jsdom';
|
|
2
|
+
import { CookieJar } from 'tough-cookie';
|
|
3
|
+
import { AxiosRequestConfig, InternalAxiosRequestConfig, AxiosResponse, AxiosRequestHeaders } from 'axios';
|
|
3
4
|
|
|
4
5
|
export interface HttpLiuGuanProxy {
|
|
5
6
|
adcode?: string
|
|
@@ -45,3 +46,4 @@ export interface HttpRequestConfig extends ExtendAxiosRequestConfig, AxiosReques
|
|
|
45
46
|
|
|
46
47
|
export interface HttpResponse extends ExtendAxiosResponse {}
|
|
47
48
|
|
|
49
|
+
export interface HTMLResponse extends JSDOM {}
|