api-def 0.12.1 → 0.13.0
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/README.md +3 -0
- package/bin/index.js +312 -313
- package/cjs/Api.d.ts +1 -1
- package/cjs/Api.js +99 -145
- package/cjs/ApiTypes.d.ts +1 -1
- package/cjs/ApiUtils.js +30 -32
- package/cjs/Endpoint.d.ts +1 -1
- package/cjs/Endpoint.js +112 -175
- package/cjs/EndpointBuilder.js +23 -32
- package/cjs/QueryHandling.js +12 -13
- package/cjs/RequestConfig.js +54 -36
- package/cjs/RequestContext.d.ts +1 -1
- package/cjs/RequestContext.js +125 -180
- package/cjs/RequestError.js +16 -19
- package/cjs/Requester.js +230 -312
- package/cjs/TextDecoding.js +31 -31
- package/cjs/Utils.js +20 -23
- package/cjs/backend/AxiosRequestBackend.d.ts +1 -1
- package/cjs/backend/AxiosRequestBackend.js +65 -172
- package/cjs/backend/FetchRequestBackend.d.ts +1 -1
- package/cjs/backend/FetchRequestBackend.js +108 -154
- package/cjs/backend/MockRequestBackend.d.ts +1 -1
- package/cjs/backend/MockRequestBackend.js +146 -208
- package/cjs/cache/ClientCaching.js +26 -74
- package/cjs/cache/LocalForageClientCacheBackend.js +15 -83
- package/cjs/cache/LocalStorageClientCacheBackend.js +14 -73
- package/cjs/index.d.ts +11 -11
- package/cjs/index.js +24 -21
- package/cjs/middleware/ClientCacheMiddleware.js +80 -103
- package/cjs/middleware/LoggingMiddleware.js +71 -42
- package/cjs/util/retry/index.js +42 -9
- package/cjs/util/retry/lib/retry.js +25 -27
- package/cjs/util/retry/lib/retryOperation.d.ts +1 -26
- package/cjs/util/retry/lib/retryOperation.js +21 -23
- package/esm/Api.d.ts +6 -6
- package/esm/Api.js +12 -25
- package/esm/ApiConstants.d.ts +1 -1
- package/esm/ApiTypes.d.ts +5 -5
- package/esm/ApiUtils.d.ts +2 -2
- package/esm/ApiUtils.js +4 -5
- package/esm/Endpoint.d.ts +6 -6
- package/esm/Endpoint.js +22 -28
- package/esm/EndpointBuilder.d.ts +4 -4
- package/esm/EndpointBuilder.js +2 -2
- package/esm/MockingTypes.d.ts +1 -1
- package/esm/QueryHandling.d.ts +1 -1
- package/esm/QueryHandling.js +2 -3
- package/esm/RequestConfig.d.ts +1 -1
- package/esm/RequestConfig.js +6 -7
- package/esm/RequestContext.d.ts +7 -7
- package/esm/RequestContext.js +15 -27
- package/esm/RequestError.d.ts +3 -3
- package/esm/RequestError.js +2 -3
- package/esm/Requester.d.ts +2 -2
- package/esm/Requester.js +44 -50
- package/esm/UtilTypes.d.ts +1 -1
- package/esm/Utils.js +2 -1
- package/esm/Validation.d.ts +1 -1
- package/esm/backend/AxiosRequestBackend.d.ts +4 -4
- package/esm/backend/AxiosRequestBackend.js +47 -84
- package/esm/backend/FetchRequestBackend.d.ts +5 -5
- package/esm/backend/FetchRequestBackend.js +49 -63
- package/esm/backend/MockRequestBackend.d.ts +4 -4
- package/esm/backend/MockRequestBackend.js +105 -136
- package/esm/backend/RequestBackend.d.ts +2 -2
- package/esm/cache/ClientCaching.d.ts +1 -1
- package/esm/cache/ClientCaching.js +8 -17
- package/esm/cache/LocalForageClientCacheBackend.d.ts +1 -1
- package/esm/cache/LocalForageClientCacheBackend.js +8 -25
- package/esm/cache/LocalStorageClientCacheBackend.d.ts +1 -1
- package/esm/cache/LocalStorageClientCacheBackend.js +9 -26
- package/esm/index.d.ts +16 -16
- package/esm/index.js +15 -15
- package/esm/middleware/ClientCacheMiddleware.d.ts +1 -1
- package/esm/middleware/ClientCacheMiddleware.js +8 -17
- package/esm/middleware/LoggingMiddleware.d.ts +1 -1
- package/esm/middleware/LoggingMiddleware.js +5 -6
- package/esm/util/retry/index.js +1 -1
- package/esm/util/retry/lib/retry.d.ts +1 -1
- package/esm/util/retry/lib/retry.js +13 -7
- package/esm/util/retry/lib/retryOperation.d.ts +1 -26
- package/esm/util/retry/lib/retryOperation.js +1 -1
- package/package.json +66 -28
package/cjs/RequestContext.js
CHANGED
|
@@ -1,55 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
-
if (ar || !(i in from)) {
|
|
41
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
-
ar[i] = from[i];
|
|
43
|
-
}
|
|
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]; } };
|
|
44
7
|
}
|
|
45
|
-
|
|
46
|
-
}
|
|
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
|
+
})();
|
|
47
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
36
|
+
const ApiUtils_1 = require("./ApiUtils");
|
|
37
|
+
const Utils = __importStar(require("./Utils"));
|
|
38
|
+
let contextIdCounter = 0;
|
|
39
|
+
class RequestContext {
|
|
40
|
+
constructor(backend, host, config, rawPath, mocking) {
|
|
53
41
|
this.canceler = null;
|
|
54
42
|
this.response = undefined;
|
|
55
43
|
this.error = null;
|
|
@@ -78,93 +66,74 @@ var RequestContext = /** @class */ (function () {
|
|
|
78
66
|
this.parseRequestBody();
|
|
79
67
|
this.computedRequestUrl = this.resolveRequestUrl();
|
|
80
68
|
}
|
|
81
|
-
|
|
69
|
+
validatePath() {
|
|
82
70
|
this.computedPath = (0, ApiUtils_1.resolvePathParams)(this.rawPath, this.requestConfig.params);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return this.host.api;
|
|
104
|
-
},
|
|
105
|
-
enumerable: false,
|
|
106
|
-
configurable: true
|
|
107
|
-
});
|
|
108
|
-
Object.defineProperty(RequestContext.prototype, "baseUrl", {
|
|
109
|
-
get: function () {
|
|
110
|
-
return this.computedBaseUrl;
|
|
111
|
-
},
|
|
112
|
-
enumerable: false,
|
|
113
|
-
configurable: true
|
|
114
|
-
});
|
|
115
|
-
Object.defineProperty(RequestContext.prototype, "responseType", {
|
|
116
|
-
get: function () {
|
|
117
|
-
return this.host.responseType;
|
|
118
|
-
},
|
|
119
|
-
enumerable: false,
|
|
120
|
-
configurable: true
|
|
121
|
-
});
|
|
122
|
-
RequestContext.prototype.initMiddleware = function () {
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated Use `requestConfig` instead
|
|
74
|
+
*/
|
|
75
|
+
get computedConfig() {
|
|
76
|
+
return this.requestConfig;
|
|
77
|
+
}
|
|
78
|
+
get method() {
|
|
79
|
+
return this.computedMethod;
|
|
80
|
+
}
|
|
81
|
+
get api() {
|
|
82
|
+
return this.host.api;
|
|
83
|
+
}
|
|
84
|
+
get baseUrl() {
|
|
85
|
+
return this.computedBaseUrl;
|
|
86
|
+
}
|
|
87
|
+
get responseType() {
|
|
88
|
+
return this.host.responseType;
|
|
89
|
+
}
|
|
90
|
+
initMiddleware() {
|
|
123
91
|
// Merge API-level and endpoint-level middleware
|
|
124
|
-
|
|
92
|
+
const allMiddleware = [
|
|
93
|
+
...this.api.middleware,
|
|
94
|
+
...("middleware" in this.host && Array.isArray(this.host.middleware) ? this.host.middleware : []),
|
|
95
|
+
];
|
|
125
96
|
// Process all middleware in one pass
|
|
126
|
-
for (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
for (
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
97
|
+
for (let i = 0; i < allMiddleware.length; i++) {
|
|
98
|
+
const events = allMiddleware[i];
|
|
99
|
+
const eventTypes = Object.keys(events);
|
|
100
|
+
for (let n = 0; n < eventTypes.length; n++) {
|
|
101
|
+
const eventType = eventTypes[n];
|
|
102
|
+
const eventHandlersForType = this.eventHandlers[eventType] || (this.eventHandlers[eventType] = []);
|
|
103
|
+
const middlewareEventHandlers = events[eventType];
|
|
133
104
|
if (middlewareEventHandlers) {
|
|
134
105
|
eventHandlersForType.push(middlewareEventHandlers);
|
|
135
106
|
}
|
|
136
107
|
}
|
|
137
108
|
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
109
|
+
}
|
|
110
|
+
generateKey() {
|
|
111
|
+
let key = this.computedPath.trim();
|
|
141
112
|
if (this.requestConfig.queryString) {
|
|
142
|
-
key +=
|
|
113
|
+
key += `?${this.requestConfig.queryString}`;
|
|
143
114
|
}
|
|
144
115
|
return key;
|
|
145
|
-
}
|
|
146
|
-
|
|
116
|
+
}
|
|
117
|
+
updateHeaders(newHeaders) {
|
|
147
118
|
this.requestConfig.headers = Utils.assign({}, this.requestConfig.headers, newHeaders);
|
|
148
119
|
this.parseRequestBody();
|
|
149
120
|
return this;
|
|
150
|
-
}
|
|
151
|
-
|
|
121
|
+
}
|
|
122
|
+
updateParams(params) {
|
|
152
123
|
this.requestConfig.params = Utils.assign({}, this.requestConfig.params, params);
|
|
153
124
|
this.computedPath = (0, ApiUtils_1.resolvePathParams)(this.rawPath, this.requestConfig.params);
|
|
154
125
|
this.computedRequestUrl = this.resolveRequestUrl();
|
|
155
126
|
return this;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
var _a;
|
|
127
|
+
}
|
|
128
|
+
parseRequestBody() {
|
|
159
129
|
if (this.requestConfig.body && this.requestConfig.headers) {
|
|
160
|
-
|
|
161
|
-
|
|
130
|
+
const contentTypeKey = Object.keys(this.requestConfig.headers).find((key) => key.toLowerCase() === "content-type");
|
|
131
|
+
const contentType = contentTypeKey && this.requestConfig.headers[contentTypeKey]?.toString().split(";")[0].trim();
|
|
162
132
|
if (contentType === "application/x-www-form-urlencoded") {
|
|
163
|
-
|
|
164
|
-
for (
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
searchParams.append(key, value === null || value === void 0 ? void 0 : value.toString());
|
|
133
|
+
const searchParams = new URLSearchParams();
|
|
134
|
+
for (const key of Object.keys(this.requestConfig.body)) {
|
|
135
|
+
const value = this.requestConfig.body[key];
|
|
136
|
+
searchParams.append(key, value?.toString());
|
|
168
137
|
}
|
|
169
138
|
this.parsedBody = searchParams;
|
|
170
139
|
}
|
|
@@ -175,89 +144,65 @@ var RequestContext = /** @class */ (function () {
|
|
|
175
144
|
else {
|
|
176
145
|
this.parsedBody = undefined;
|
|
177
146
|
}
|
|
178
|
-
}
|
|
179
|
-
|
|
147
|
+
}
|
|
148
|
+
getParsedBody() {
|
|
180
149
|
return this.parsedBody;
|
|
181
|
-
}
|
|
182
|
-
|
|
150
|
+
}
|
|
151
|
+
updateQuery(newQuery) {
|
|
183
152
|
this.requestConfig.queryObject = Utils.assign({}, this.requestConfig.queryObject, newQuery);
|
|
184
153
|
this.computedRequestUrl = this.resolveRequestUrl();
|
|
185
154
|
return this;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
i = 0;
|
|
196
|
-
_a.label = 1;
|
|
197
|
-
case 1:
|
|
198
|
-
if (!(i < eventHandlers.length)) return [3 /*break*/, 4];
|
|
199
|
-
eventHandler = eventHandlers[i];
|
|
200
|
-
return [4 /*yield*/, eventHandler(this)];
|
|
201
|
-
case 2:
|
|
202
|
-
eventResult = _a.sent();
|
|
203
|
-
if (eventResult) {
|
|
204
|
-
return [2 /*return*/, eventResult];
|
|
205
|
-
}
|
|
206
|
-
_a.label = 3;
|
|
207
|
-
case 3:
|
|
208
|
-
i++;
|
|
209
|
-
return [3 /*break*/, 1];
|
|
210
|
-
case 4: return [2 /*return*/, undefined];
|
|
155
|
+
}
|
|
156
|
+
async triggerEvent(eventType) {
|
|
157
|
+
const eventHandlers = this.eventHandlers[eventType];
|
|
158
|
+
if (eventHandlers) {
|
|
159
|
+
for (let i = 0; i < eventHandlers.length; i++) {
|
|
160
|
+
const eventHandler = eventHandlers[i];
|
|
161
|
+
const eventResult = await eventHandler(this);
|
|
162
|
+
if (eventResult) {
|
|
163
|
+
return eventResult;
|
|
211
164
|
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
addCanceller(canceler) {
|
|
216
170
|
this.canceler = canceler;
|
|
217
|
-
}
|
|
218
|
-
|
|
171
|
+
}
|
|
172
|
+
cancel() {
|
|
219
173
|
this.cancelled = true;
|
|
220
174
|
if (this.canceler) {
|
|
221
175
|
this.canceler();
|
|
222
176
|
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
Object.defineProperty(RequestContext.prototype, "path", {
|
|
232
|
-
get: function () {
|
|
233
|
-
return this.computedPath;
|
|
234
|
-
},
|
|
235
|
-
enumerable: false,
|
|
236
|
-
configurable: true
|
|
237
|
-
});
|
|
238
|
-
RequestContext.prototype.updatePath = function (path) {
|
|
177
|
+
}
|
|
178
|
+
get requestUrl() {
|
|
179
|
+
return this.computedRequestUrl;
|
|
180
|
+
}
|
|
181
|
+
get path() {
|
|
182
|
+
return this.computedPath;
|
|
183
|
+
}
|
|
184
|
+
updatePath(path) {
|
|
239
185
|
this.computedPath = path;
|
|
240
186
|
this.computedRequestUrl = this.resolveRequestUrl();
|
|
241
|
-
}
|
|
242
|
-
|
|
187
|
+
}
|
|
188
|
+
updateBaseUrl(baseUrl) {
|
|
243
189
|
this.computedBaseUrl = baseUrl;
|
|
244
190
|
this.computedRequestUrl = this.resolveRequestUrl();
|
|
245
|
-
}
|
|
246
|
-
|
|
191
|
+
}
|
|
192
|
+
updateMethod(method) {
|
|
247
193
|
this.computedMethod = method;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// @ts-
|
|
194
|
+
}
|
|
195
|
+
updateBody(body) {
|
|
196
|
+
// @ts-expect-error
|
|
251
197
|
this.requestConfig.body = body;
|
|
252
198
|
this.parseRequestBody();
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
199
|
+
}
|
|
200
|
+
resolveRequestUrl() {
|
|
201
|
+
const url = (0, ApiUtils_1.resolveUrl)({ baseUrl: this.baseUrl, path: this.computedPath });
|
|
256
202
|
if (this.requestConfig.queryString) {
|
|
257
203
|
url.search = this.requestConfig.queryString;
|
|
258
204
|
}
|
|
259
205
|
return url;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
}());
|
|
206
|
+
}
|
|
207
|
+
}
|
|
263
208
|
exports.default = RequestContext;
|
package/cjs/RequestError.js
CHANGED
|
@@ -13,8 +13,8 @@ exports.RequestErrorCode = {
|
|
|
13
13
|
VALIDATION_BODY_VALIDATE_ERROR: "validation/body-validate-error",
|
|
14
14
|
VALIDATION_RESPONSE_VALIDATE_ERROR: "validation/response-validate-error",
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const REQUEST_ERROR_SYMBOL = "isApiDefError";
|
|
17
|
+
const isRequestError = (error) => {
|
|
18
18
|
if (!error) {
|
|
19
19
|
return false;
|
|
20
20
|
}
|
|
@@ -24,10 +24,9 @@ var isRequestError = function (error) {
|
|
|
24
24
|
return error[REQUEST_ERROR_SYMBOL] === true;
|
|
25
25
|
};
|
|
26
26
|
exports.isRequestError = isRequestError;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var body = context.getParsedBody();
|
|
27
|
+
const convertToRequestError = (config) => {
|
|
28
|
+
const { error, context, response, code } = config;
|
|
29
|
+
const body = context.getParsedBody();
|
|
31
30
|
if (error.constructor.name === "TypeError") {
|
|
32
31
|
error.constructor = TypeError;
|
|
33
32
|
Object.setPrototypeOf(error, TypeError.prototype);
|
|
@@ -36,23 +35,22 @@ var convertToRequestError = function (config) {
|
|
|
36
35
|
error.constructor = Error;
|
|
37
36
|
Object.setPrototypeOf(error, Error.prototype);
|
|
38
37
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
_a.request = {
|
|
38
|
+
const resultError = Object.assign(error, {
|
|
39
|
+
name: "RequestError",
|
|
40
|
+
response: response,
|
|
41
|
+
code: code,
|
|
42
|
+
[REQUEST_ERROR_SYMBOL]: true,
|
|
43
|
+
attempts: context.stats.attempt,
|
|
44
|
+
request: {
|
|
47
45
|
url: context.requestUrl.href,
|
|
48
46
|
query: context.requestConfig.queryObject,
|
|
49
47
|
headers: context.requestConfig.headers,
|
|
50
48
|
body: body,
|
|
51
49
|
},
|
|
52
|
-
|
|
50
|
+
});
|
|
53
51
|
try {
|
|
54
52
|
Object.defineProperty(resultError, "message", {
|
|
55
|
-
value:
|
|
53
|
+
value: `A ${context.method.toUpperCase()} request to '${context.requestUrl.href}' failed${response?.status ? ` with status code ${response.status}` : ""} [${code}]: ${resultError.message}`,
|
|
56
54
|
});
|
|
57
55
|
}
|
|
58
56
|
catch (e) {
|
|
@@ -63,10 +61,9 @@ var convertToRequestError = function (config) {
|
|
|
63
61
|
return resultError;
|
|
64
62
|
};
|
|
65
63
|
exports.convertToRequestError = convertToRequestError;
|
|
66
|
-
|
|
67
|
-
var _a;
|
|
64
|
+
const getErrorResponse = (error) => {
|
|
68
65
|
if ((0, exports.isRequestError)(error)) {
|
|
69
|
-
return
|
|
66
|
+
return error.response ?? undefined;
|
|
70
67
|
}
|
|
71
68
|
return undefined;
|
|
72
69
|
};
|