@dynatrace-sdk/http-client 0.4.11 → 1.0.3
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/CHANGELOG.md
CHANGED
|
@@ -2,128 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
@dynatrace-sdk/http-client
|
|
4
4
|
|
|
5
|
-
## 0.
|
|
5
|
+
## 1.0.3
|
|
6
6
|
|
|
7
7
|
### Patch Changes
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
- Updated dependencies
|
|
9
|
+
- fcaf3292: Add optional `errorRef` to `SerializedError`
|
|
10
|
+
- Updated dependencies [fcaf3292]
|
|
11
|
+
- @dynatrace-sdk/error-handlers@1.1.0
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## 0.4.10
|
|
15
|
-
|
|
16
|
-
### Patch Changes
|
|
17
|
-
|
|
18
|
-
- Trimming multipart content-type headers.
|
|
19
|
-
|
|
20
|
-
## 0.4.9
|
|
21
|
-
|
|
22
|
-
### Patch Changes
|
|
23
|
-
|
|
24
|
-
- 1f33e503: Bumped @dynatrace-sdk/error-handlers dependency
|
|
25
|
-
|
|
26
|
-
## 0.4.8
|
|
27
|
-
|
|
28
|
-
### Patch Changes
|
|
29
|
-
|
|
30
|
-
- In error serializer unwrap a message from an error wrapped by the HttpSerializedError.
|
|
31
|
-
- Updated dependencies
|
|
32
|
-
|
|
33
|
-
- Updated dependencies
|
|
34
|
-
|
|
35
|
-
- @dynatrace-sdk/error-handlers@0.1.1
|
|
36
|
-
|
|
37
|
-
## 0.4.7
|
|
38
|
-
|
|
39
|
-
### Patch Changes
|
|
40
|
-
|
|
41
|
-
- Updated dependencies
|
|
42
|
-
|
|
43
|
-
- @dynatrace-sdk/error-handlers@0.1.0
|
|
44
|
-
|
|
45
|
-
## 0.4.6
|
|
46
|
-
|
|
47
|
-
### Patch Changes
|
|
48
|
-
|
|
49
|
-
- Refactor error serializer registering logic.
|
|
50
|
-
|
|
51
|
-
## 0.4.5
|
|
52
|
-
|
|
53
|
-
### Patch Changes
|
|
54
|
-
|
|
55
|
-
- Remove `@dynatrace/sdk-web` dependency from `http-client`.
|
|
56
|
-
|
|
57
|
-
## 0.4.4
|
|
58
|
-
|
|
59
|
-
### Patch Changes
|
|
60
|
-
|
|
61
|
-
- Convey Blob.type to Content-Type header for form field.
|
|
62
|
-
|
|
63
|
-
## 0.4.3
|
|
64
|
-
|
|
65
|
-
### Patch Changes
|
|
66
|
-
|
|
67
|
-
- Adjust autogenerated docs to the latest template view.
|
|
68
|
-
|
|
69
|
-
## 0.4.2
|
|
70
|
-
|
|
71
|
-
### Patch Changes
|
|
72
|
-
|
|
73
|
-
- Fix aborted fetch causing throwing "DataTypeError".
|
|
74
|
-
|
|
75
|
-
## 0.4.1
|
|
76
|
-
|
|
77
|
-
### Patch Changes
|
|
78
|
-
|
|
79
|
-
- Add File type support to FormData request body.
|
|
80
|
-
- Fixed typings of PlatformAbortController and PlatformAbortSignal
|
|
81
|
-
|
|
82
|
-
## 0.4.0
|
|
83
|
-
|
|
84
|
-
### Minor Changes
|
|
85
|
-
|
|
86
|
-
- Adjust AbortSignal typing to current TypeScript version (4.7.4).
|
|
87
|
-
|
|
88
|
-
## 0.3.1
|
|
89
|
-
|
|
90
|
-
### Patch Changes
|
|
91
|
-
|
|
92
|
-
- Add markdown documentation to each package inside `/docs` folder
|
|
93
|
-
|
|
94
|
-
## 0.3.0
|
|
95
|
-
|
|
96
|
-
### Minor Changes
|
|
97
|
-
|
|
98
|
-
- Expose both ESM and CJS modules.
|
|
99
|
-
|
|
100
|
-
## 0.2.1
|
|
101
|
-
|
|
102
|
-
### Patch Changes
|
|
103
|
-
|
|
104
|
-
- Change namespace of http-client to @dynatrace-sdk.
|
|
105
|
-
|
|
106
|
-
## 0.2.0
|
|
107
|
-
|
|
108
|
-
### Minor Changes
|
|
109
|
-
|
|
110
|
-
- Fix for sending proper payload contents when Binary datatype is passed.
|
|
111
|
-
|
|
112
|
-
## 0.1.2
|
|
13
|
+
## 1.0.2
|
|
113
14
|
|
|
114
15
|
### Patch Changes
|
|
115
16
|
|
|
116
|
-
-
|
|
17
|
+
- 95c93964: Add message of original error to HttpClientRequestError.
|
|
117
18
|
|
|
118
|
-
## 0.1
|
|
19
|
+
## 1.0.1
|
|
119
20
|
|
|
120
21
|
### Patch Changes
|
|
121
22
|
|
|
122
|
-
-
|
|
123
|
-
- Add global serializer for http errors.
|
|
23
|
+
- 6d104a97: Parse response body in global error serializer
|
|
124
24
|
|
|
125
|
-
##
|
|
25
|
+
## 1.0.0
|
|
126
26
|
|
|
127
|
-
###
|
|
27
|
+
### Major Changes
|
|
128
28
|
|
|
129
|
-
-
|
|
29
|
+
- Initial public release.
|
package/cjs/index.js
CHANGED
|
@@ -257,7 +257,7 @@ var HttpClientAbortError = class extends Error {
|
|
|
257
257
|
name = "AbortError";
|
|
258
258
|
};
|
|
259
259
|
var throwIfAbortError = (e) => {
|
|
260
|
-
if (e instanceof
|
|
260
|
+
if (e instanceof Error && e.name === "AbortError") {
|
|
261
261
|
throw new HttpClientAbortError(e);
|
|
262
262
|
}
|
|
263
263
|
};
|
|
@@ -265,7 +265,9 @@ var throwIfAbortError = (e) => {
|
|
|
265
265
|
// packages/http-client/src/lib/platform/http-client-request-error.ts
|
|
266
266
|
var HttpClientRequestError = class extends BaseError {
|
|
267
267
|
constructor(cause) {
|
|
268
|
-
super(
|
|
268
|
+
super(
|
|
269
|
+
typeof cause?.message === "string" ? `Request failed: ${cause.message}` : "Request failed."
|
|
270
|
+
);
|
|
269
271
|
this.cause = cause;
|
|
270
272
|
}
|
|
271
273
|
name = "RequestError";
|
|
@@ -410,28 +412,47 @@ var HttpClientResponse = class {
|
|
|
410
412
|
|
|
411
413
|
// packages/http-client/src/lib/platform/http-client-response-error-serializer.ts
|
|
412
414
|
var import_error_handlers = require("@dynatrace-sdk/error-handlers");
|
|
413
|
-
|
|
415
|
+
function getMessageFromObject(obj) {
|
|
416
|
+
if (typeof obj === "object" && obj !== null && typeof obj.message === "string") {
|
|
417
|
+
return obj.message;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
async function parseResponse(response) {
|
|
414
421
|
const consumedBody = await response.body("text");
|
|
415
422
|
try {
|
|
416
423
|
const jsonBody = JSON.parse(consumedBody);
|
|
417
|
-
if (
|
|
418
|
-
return
|
|
424
|
+
if (typeof jsonBody === "object" && jsonBody !== null) {
|
|
425
|
+
return {
|
|
426
|
+
message: getMessageFromObject(jsonBody.error) || getMessageFromObject(jsonBody) || consumedBody.substring(0, 100),
|
|
427
|
+
body: jsonBody,
|
|
428
|
+
errorRef: jsonBody.error?.details?.errorRef
|
|
429
|
+
};
|
|
430
|
+
} else {
|
|
431
|
+
return {
|
|
432
|
+
message: consumedBody.substring(0, 100),
|
|
433
|
+
body: consumedBody
|
|
434
|
+
};
|
|
419
435
|
}
|
|
420
436
|
} catch (e) {
|
|
421
|
-
return
|
|
437
|
+
return {
|
|
438
|
+
message: consumedBody.substring(0, 100),
|
|
439
|
+
body: consumedBody
|
|
440
|
+
};
|
|
422
441
|
}
|
|
423
|
-
return consumedBody.substring(0, 100);
|
|
424
442
|
}
|
|
425
443
|
var httpClientResponseErrorSerializer = async (error) => {
|
|
426
444
|
if (error instanceof HttpClientResponseError) {
|
|
427
445
|
const status = error.response.status;
|
|
428
|
-
const message = await
|
|
446
|
+
const { message, body, errorRef } = await parseResponse(error.response);
|
|
447
|
+
const optionalErrorRef = errorRef ? { errorRef } : {};
|
|
429
448
|
return {
|
|
430
449
|
name: error.name,
|
|
431
450
|
status,
|
|
432
451
|
message,
|
|
433
452
|
stack: error.stack,
|
|
434
|
-
type: import_error_handlers.ErrorType.HTTP
|
|
453
|
+
type: import_error_handlers.ErrorType.HTTP,
|
|
454
|
+
body,
|
|
455
|
+
...optionalErrorRef
|
|
435
456
|
};
|
|
436
457
|
}
|
|
437
458
|
};
|
package/docs/DOCS.md
CHANGED
package/esm/index.js
CHANGED
|
@@ -221,7 +221,7 @@ var HttpClientAbortError = class extends Error {
|
|
|
221
221
|
name = "AbortError";
|
|
222
222
|
};
|
|
223
223
|
var throwIfAbortError = (e) => {
|
|
224
|
-
if (e instanceof
|
|
224
|
+
if (e instanceof Error && e.name === "AbortError") {
|
|
225
225
|
throw new HttpClientAbortError(e);
|
|
226
226
|
}
|
|
227
227
|
};
|
|
@@ -229,7 +229,9 @@ var throwIfAbortError = (e) => {
|
|
|
229
229
|
// packages/http-client/src/lib/platform/http-client-request-error.ts
|
|
230
230
|
var HttpClientRequestError = class extends BaseError {
|
|
231
231
|
constructor(cause) {
|
|
232
|
-
super(
|
|
232
|
+
super(
|
|
233
|
+
typeof cause?.message === "string" ? `Request failed: ${cause.message}` : "Request failed."
|
|
234
|
+
);
|
|
233
235
|
this.cause = cause;
|
|
234
236
|
}
|
|
235
237
|
name = "RequestError";
|
|
@@ -378,28 +380,47 @@ import {
|
|
|
378
380
|
ErrorType,
|
|
379
381
|
isGlobalErrorSerializerSupported
|
|
380
382
|
} from "@dynatrace-sdk/error-handlers";
|
|
381
|
-
|
|
383
|
+
function getMessageFromObject(obj) {
|
|
384
|
+
if (typeof obj === "object" && obj !== null && typeof obj.message === "string") {
|
|
385
|
+
return obj.message;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
async function parseResponse(response) {
|
|
382
389
|
const consumedBody = await response.body("text");
|
|
383
390
|
try {
|
|
384
391
|
const jsonBody = JSON.parse(consumedBody);
|
|
385
|
-
if (
|
|
386
|
-
return
|
|
392
|
+
if (typeof jsonBody === "object" && jsonBody !== null) {
|
|
393
|
+
return {
|
|
394
|
+
message: getMessageFromObject(jsonBody.error) || getMessageFromObject(jsonBody) || consumedBody.substring(0, 100),
|
|
395
|
+
body: jsonBody,
|
|
396
|
+
errorRef: jsonBody.error?.details?.errorRef
|
|
397
|
+
};
|
|
398
|
+
} else {
|
|
399
|
+
return {
|
|
400
|
+
message: consumedBody.substring(0, 100),
|
|
401
|
+
body: consumedBody
|
|
402
|
+
};
|
|
387
403
|
}
|
|
388
404
|
} catch (e) {
|
|
389
|
-
return
|
|
405
|
+
return {
|
|
406
|
+
message: consumedBody.substring(0, 100),
|
|
407
|
+
body: consumedBody
|
|
408
|
+
};
|
|
390
409
|
}
|
|
391
|
-
return consumedBody.substring(0, 100);
|
|
392
410
|
}
|
|
393
411
|
var httpClientResponseErrorSerializer = async (error) => {
|
|
394
412
|
if (error instanceof HttpClientResponseError) {
|
|
395
413
|
const status = error.response.status;
|
|
396
|
-
const message = await
|
|
414
|
+
const { message, body, errorRef } = await parseResponse(error.response);
|
|
415
|
+
const optionalErrorRef = errorRef ? { errorRef } : {};
|
|
397
416
|
return {
|
|
398
417
|
name: error.name,
|
|
399
418
|
status,
|
|
400
419
|
message,
|
|
401
420
|
stack: error.stack,
|
|
402
|
-
type: ErrorType.HTTP
|
|
421
|
+
type: ErrorType.HTTP,
|
|
422
|
+
body,
|
|
423
|
+
...optionalErrorRef
|
|
403
424
|
};
|
|
404
425
|
}
|
|
405
426
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynatrace-sdk/http-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@dynatrace-sdk/error-handlers": "^
|
|
6
|
+
"@dynatrace-sdk/error-handlers": "^1.1.0"
|
|
7
7
|
},
|
|
8
8
|
"main": "./cjs/index.js",
|
|
9
9
|
"module": "./esm/index.js",
|