@dynatrace-sdk/http-client 0.4.5 → 0.4.9
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 +31 -0
- package/cjs/index.js +19 -9
- package/docs/DOCS.md +1 -1
- package/esm/index.js +23 -9
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
@dynatrace-sdk/http-client
|
|
4
4
|
|
|
5
|
+
## 0.4.9
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- 1f33e503: Bumped @dynatrace-sdk/error-handlers dependency
|
|
10
|
+
|
|
11
|
+
## 0.4.8
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- In error serializer unwrap a message from an error wrapped by the HttpSerializedError.
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
|
|
20
|
+
- @dynatrace-sdk/error-handlers@0.1.1
|
|
21
|
+
|
|
22
|
+
## 0.4.7
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated dependencies
|
|
27
|
+
|
|
28
|
+
- @dynatrace-sdk/error-handlers@0.1.0
|
|
29
|
+
|
|
30
|
+
## 0.4.6
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Refactor error serializer registering logic.
|
|
35
|
+
|
|
5
36
|
## 0.4.5
|
|
6
37
|
|
|
7
38
|
### Patch Changes
|
package/cjs/index.js
CHANGED
|
@@ -386,29 +386,39 @@ var HttpClientResponse = class {
|
|
|
386
386
|
};
|
|
387
387
|
|
|
388
388
|
// packages/http-client/src/lib/platform/http-client-response-error-serializer.ts
|
|
389
|
-
var
|
|
390
|
-
function
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
389
|
+
var import_error_handlers = require("@dynatrace-sdk/error-handlers");
|
|
390
|
+
async function getMessage(response) {
|
|
391
|
+
const consumedBody = await response.body("text");
|
|
392
|
+
try {
|
|
393
|
+
const jsonBody = JSON.parse(consumedBody);
|
|
394
|
+
if (jsonBody.message && typeof jsonBody.message === "string") {
|
|
395
|
+
return jsonBody.message;
|
|
396
396
|
}
|
|
397
|
+
} catch (e) {
|
|
398
|
+
return consumedBody.substring(0, 100);
|
|
397
399
|
}
|
|
400
|
+
return consumedBody.substring(0, 100);
|
|
398
401
|
}
|
|
399
402
|
var httpClientResponseErrorSerializer = async (error) => {
|
|
400
403
|
if (error instanceof HttpClientResponseError) {
|
|
401
404
|
const status = error.response.status;
|
|
402
|
-
const message = await error.response
|
|
405
|
+
const message = await getMessage(error.response);
|
|
403
406
|
return {
|
|
404
407
|
name: error.name,
|
|
405
408
|
status,
|
|
406
409
|
message,
|
|
407
410
|
stack: error.stack,
|
|
408
|
-
type:
|
|
411
|
+
type: import_error_handlers.ErrorType.HTTP
|
|
409
412
|
};
|
|
410
413
|
}
|
|
411
414
|
};
|
|
415
|
+
var errorSerializerAdded = false;
|
|
416
|
+
function addHttpClientResponseErrorSerializer() {
|
|
417
|
+
if (!errorSerializerAdded && (0, import_error_handlers.isGlobalErrorSerializerSupported)()) {
|
|
418
|
+
errorSerializerAdded = true;
|
|
419
|
+
(0, import_error_handlers.addGlobalErrorSerializer)(httpClientResponseErrorSerializer);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
412
422
|
|
|
413
423
|
// packages/http-client/src/lib/platform/http-client-response-error.ts
|
|
414
424
|
var HttpClientResponseError = class extends BaseError {
|
package/docs/DOCS.md
CHANGED
package/esm/index.js
CHANGED
|
@@ -349,29 +349,43 @@ var HttpClientResponse = class {
|
|
|
349
349
|
};
|
|
350
350
|
|
|
351
351
|
// packages/http-client/src/lib/platform/http-client-response-error-serializer.ts
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
352
|
+
import {
|
|
353
|
+
addGlobalErrorSerializer,
|
|
354
|
+
ErrorType,
|
|
355
|
+
isGlobalErrorSerializerSupported
|
|
356
|
+
} from "@dynatrace-sdk/error-handlers";
|
|
357
|
+
async function getMessage(response) {
|
|
358
|
+
const consumedBody = await response.body("text");
|
|
359
|
+
try {
|
|
360
|
+
const jsonBody = JSON.parse(consumedBody);
|
|
361
|
+
if (jsonBody.message && typeof jsonBody.message === "string") {
|
|
362
|
+
return jsonBody.message;
|
|
359
363
|
}
|
|
364
|
+
} catch (e) {
|
|
365
|
+
return consumedBody.substring(0, 100);
|
|
360
366
|
}
|
|
367
|
+
return consumedBody.substring(0, 100);
|
|
361
368
|
}
|
|
362
369
|
var httpClientResponseErrorSerializer = async (error) => {
|
|
363
370
|
if (error instanceof HttpClientResponseError) {
|
|
364
371
|
const status = error.response.status;
|
|
365
|
-
const message = await error.response
|
|
372
|
+
const message = await getMessage(error.response);
|
|
366
373
|
return {
|
|
367
374
|
name: error.name,
|
|
368
375
|
status,
|
|
369
376
|
message,
|
|
370
377
|
stack: error.stack,
|
|
371
|
-
type:
|
|
378
|
+
type: ErrorType.HTTP
|
|
372
379
|
};
|
|
373
380
|
}
|
|
374
381
|
};
|
|
382
|
+
var errorSerializerAdded = false;
|
|
383
|
+
function addHttpClientResponseErrorSerializer() {
|
|
384
|
+
if (!errorSerializerAdded && isGlobalErrorSerializerSupported()) {
|
|
385
|
+
errorSerializerAdded = true;
|
|
386
|
+
addGlobalErrorSerializer(httpClientResponseErrorSerializer);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
375
389
|
|
|
376
390
|
// packages/http-client/src/lib/platform/http-client-response-error.ts
|
|
377
391
|
var HttpClientResponseError = class extends BaseError {
|
package/package.json
CHANGED