@dynatrace-sdk/http-client 1.0.3 → 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,28 +2,36 @@
2
2
 
3
3
  @dynatrace-sdk/http-client
4
4
 
5
+ ## 1.0.4
6
+
7
+ ### Patch Changes
8
+
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.
11
+
5
12
  ## 1.0.3
6
13
 
7
14
  ### Patch Changes
8
15
 
9
- - fcaf3292: Add optional `errorRef` to `SerializedError`
10
- - Updated dependencies [fcaf3292]
16
+ - Add optional `errorRef` to `SerializedError`
17
+ - Updated dependencies
18
+
11
19
  - @dynatrace-sdk/error-handlers@1.1.0
12
20
 
13
21
  ## 1.0.2
14
22
 
15
23
  ### Patch Changes
16
24
 
17
- - 95c93964: Add message of original error to HttpClientRequestError.
25
+ - Add message of original error to HttpClientRequestError.
18
26
 
19
27
  ## 1.0.1
20
28
 
21
29
  ### Patch Changes
22
30
 
23
- - 6d104a97: Parse response body in global error serializer
31
+ - Parse response body in global error serializer
24
32
 
25
33
  ## 1.0.0
26
34
 
27
35
  ### Major Changes
28
36
 
29
- - Initial public release.
37
+ - Initial public release.
package/cjs/index.js CHANGED
@@ -325,6 +325,14 @@ async function decodeBlobResponseBody(response) {
325
325
  function decodeReadableStreamResponseBody(response) {
326
326
  return response.body !== null ? response.body : emptyReadableStream();
327
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
+ }
328
336
  async function decodeAsyncResponseBody(response, responseBodyType) {
329
337
  try {
330
338
  switch (responseBodyType) {
@@ -343,10 +351,7 @@ async function decodeAsyncResponseBody(response, responseBodyType) {
343
351
  }
344
352
  } catch (e) {
345
353
  throwIfAbortError(e);
346
- throw new DataTypeError(
347
- `Response body does not conform to the specified response body type: '${responseBodyType}'.`,
348
- e
349
- );
354
+ throwResponseBodyTypeError(response, responseBodyType, e);
350
355
  }
351
356
  }
352
357
  function decodeSyncResponseBody(response, responseBodyType) {
@@ -354,10 +359,7 @@ function decodeSyncResponseBody(response, responseBodyType) {
354
359
  return decodeReadableStreamResponseBody(response);
355
360
  } catch (e) {
356
361
  throwIfAbortError(e);
357
- throw new DataTypeError(
358
- `Response body does not conform to the specified response body type: '${responseBodyType}'.`,
359
- e
360
- );
362
+ throwResponseBodyTypeError(response, responseBodyType, e);
361
363
  }
362
364
  }
363
365
  function decodeResponseBodyImpl(response, responseBodyType) {
@@ -418,7 +420,16 @@ function getMessageFromObject(obj) {
418
420
  }
419
421
  }
420
422
  async function parseResponse(response) {
421
- const consumedBody = await response.body("text");
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
+ }
422
433
  try {
423
434
  const jsonBody = JSON.parse(consumedBody);
424
435
  if (typeof jsonBody === "object" && jsonBody !== null) {