@dynatrace-sdk/http-client 0.4.11 → 1.0.4

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,36 @@
2
2
 
3
3
  @dynatrace-sdk/http-client
4
4
 
5
- ## 0.4.11
5
+ ## 1.0.4
6
6
 
7
7
  ### Patch Changes
8
8
 
9
- - Set missing package license.
10
- - Updated dependencies
11
-
12
- - @dynatrace-sdk/error-handlers@0.2.7
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
9
+ - Content-Type header value is now present in the response body type error message.
10
+ - HttpResponseError serializer is not failing because of response body type error anymore.
32
11
 
33
- - Updated dependencies
34
-
35
- - @dynatrace-sdk/error-handlers@0.1.1
36
-
37
- ## 0.4.7
12
+ ## 1.0.3
38
13
 
39
14
  ### Patch Changes
40
15
 
16
+ - Add optional `errorRef` to `SerializedError`
41
17
  - Updated dependencies
42
18
 
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.
19
+ - @dynatrace-sdk/error-handlers@1.1.0
111
20
 
112
- ## 0.1.2
21
+ ## 1.0.2
113
22
 
114
23
  ### Patch Changes
115
24
 
116
- - Bump sdk-web to version 0.5.12 to support http-client errors in app-shell.
25
+ - Add message of original error to HttpClientRequestError.
117
26
 
118
- ## 0.1.1
27
+ ## 1.0.1
119
28
 
120
29
  ### Patch Changes
121
30
 
122
- - Add content-type header based on request body type.
123
- - Add global serializer for http errors.
31
+ - Parse response body in global error serializer
124
32
 
125
- ## 0.1.0
33
+ ## 1.0.0
126
34
 
127
- ### Minor Changes
35
+ ### Major Changes
128
36
 
129
- - Added HttpClient implementation.
37
+ - 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 DOMException && e.name === "AbortError") {
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("Request failed.");
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";
@@ -323,6 +325,14 @@ async function decodeBlobResponseBody(response) {
323
325
  function decodeReadableStreamResponseBody(response) {
324
326
  return response.body !== null ? response.body : emptyReadableStream();
325
327
  }
328
+ function throwResponseBodyTypeError(response, responseBodyType, cause) {
329
+ throw new DataTypeError(
330
+ `Response body does not conform to the specified response body type: '${responseBodyType}'. The content type of the response is '${response.headers.get(
331
+ "Content-Type"
332
+ )}'.`,
333
+ cause
334
+ );
335
+ }
326
336
  async function decodeAsyncResponseBody(response, responseBodyType) {
327
337
  try {
328
338
  switch (responseBodyType) {
@@ -341,10 +351,7 @@ async function decodeAsyncResponseBody(response, responseBodyType) {
341
351
  }
342
352
  } catch (e) {
343
353
  throwIfAbortError(e);
344
- throw new DataTypeError(
345
- `Response body does not conform to the specified response body type: '${responseBodyType}'.`,
346
- e
347
- );
354
+ throwResponseBodyTypeError(response, responseBodyType, e);
348
355
  }
349
356
  }
350
357
  function decodeSyncResponseBody(response, responseBodyType) {
@@ -352,10 +359,7 @@ function decodeSyncResponseBody(response, responseBodyType) {
352
359
  return decodeReadableStreamResponseBody(response);
353
360
  } catch (e) {
354
361
  throwIfAbortError(e);
355
- throw new DataTypeError(
356
- `Response body does not conform to the specified response body type: '${responseBodyType}'.`,
357
- e
358
- );
362
+ throwResponseBodyTypeError(response, responseBodyType, e);
359
363
  }
360
364
  }
361
365
  function decodeResponseBodyImpl(response, responseBodyType) {
@@ -410,28 +414,56 @@ var HttpClientResponse = class {
410
414
 
411
415
  // packages/http-client/src/lib/platform/http-client-response-error-serializer.ts
412
416
  var import_error_handlers = require("@dynatrace-sdk/error-handlers");
413
- async function getMessage(response) {
414
- const consumedBody = await response.body("text");
417
+ function getMessageFromObject(obj) {
418
+ if (typeof obj === "object" && obj !== null && typeof obj.message === "string") {
419
+ return obj.message;
420
+ }
421
+ }
422
+ async function parseResponse(response) {
423
+ let consumedBody;
424
+ try {
425
+ consumedBody = await response.body("text");
426
+ } catch (e) {
427
+ const bodyError = `Response body is not available. ${e?.message ?? "Unknown error occurred."}`;
428
+ return {
429
+ message: bodyError.substring(0, 100),
430
+ body: bodyError
431
+ };
432
+ }
415
433
  try {
416
434
  const jsonBody = JSON.parse(consumedBody);
417
- if (jsonBody.message && typeof jsonBody.message === "string") {
418
- return jsonBody.message;
435
+ if (typeof jsonBody === "object" && jsonBody !== null) {
436
+ return {
437
+ message: getMessageFromObject(jsonBody.error) || getMessageFromObject(jsonBody) || consumedBody.substring(0, 100),
438
+ body: jsonBody,
439
+ errorRef: jsonBody.error?.details?.errorRef
440
+ };
441
+ } else {
442
+ return {
443
+ message: consumedBody.substring(0, 100),
444
+ body: consumedBody
445
+ };
419
446
  }
420
447
  } catch (e) {
421
- return consumedBody.substring(0, 100);
448
+ return {
449
+ message: consumedBody.substring(0, 100),
450
+ body: consumedBody
451
+ };
422
452
  }
423
- return consumedBody.substring(0, 100);
424
453
  }
425
454
  var httpClientResponseErrorSerializer = async (error) => {
426
455
  if (error instanceof HttpClientResponseError) {
427
456
  const status = error.response.status;
428
- const message = await getMessage(error.response);
457
+ const { message, body, errorRef } = await parseResponse(error.response);
458
+ const optionalErrorRef = errorRef ? { errorRef } : {};
429
459
  return {
430
460
  name: error.name,
431
461
  status,
432
462
  message,
433
463
  stack: error.stack,
434
- type: import_error_handlers.ErrorType.HTTP
464
+ type: import_error_handlers.ErrorType.HTTP,
465
+ body,
466
+ ...optionalErrorRef
435
467
  };
436
468
  }
437
469
  };