@dynatrace-sdk/http-client 1.0.3 → 1.0.5

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,42 @@
2
2
 
3
3
  @dynatrace-sdk/http-client
4
4
 
5
+ ## 1.0.5
6
+
7
+ ### Patch Changes
8
+
9
+ - Add response status and response source to DataTypeError.
10
+
11
+ ## 1.0.4
12
+
13
+ ### Patch Changes
14
+
15
+ - Content-Type header value is now present in the response body type error message.
16
+ - HttpResponseError serializer is not failing because of response body type error anymore.
17
+
5
18
  ## 1.0.3
6
19
 
7
20
  ### Patch Changes
8
21
 
9
- - fcaf3292: Add optional `errorRef` to `SerializedError`
10
- - Updated dependencies [fcaf3292]
22
+ - Add optional `errorRef` to `SerializedError`
23
+ - Updated dependencies
24
+
11
25
  - @dynatrace-sdk/error-handlers@1.1.0
12
26
 
13
27
  ## 1.0.2
14
28
 
15
29
  ### Patch Changes
16
30
 
17
- - 95c93964: Add message of original error to HttpClientRequestError.
31
+ - Add message of original error to HttpClientRequestError.
18
32
 
19
33
  ## 1.0.1
20
34
 
21
35
  ### Patch Changes
22
36
 
23
- - 6d104a97: Parse response body in global error serializer
37
+ - Parse response body in global error serializer
24
38
 
25
39
  ## 1.0.0
26
40
 
27
41
  ### Major Changes
28
42
 
29
- - Initial public release.
43
+ - Initial public release.
package/cjs/index.js CHANGED
@@ -325,6 +325,16 @@ 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
+ )}'. Response status is '${response.status}'. Response source is '${response.headers.get(
333
+ "dynatrace-response-source"
334
+ )}'`,
335
+ cause
336
+ );
337
+ }
328
338
  async function decodeAsyncResponseBody(response, responseBodyType) {
329
339
  try {
330
340
  switch (responseBodyType) {
@@ -343,10 +353,7 @@ async function decodeAsyncResponseBody(response, responseBodyType) {
343
353
  }
344
354
  } catch (e) {
345
355
  throwIfAbortError(e);
346
- throw new DataTypeError(
347
- `Response body does not conform to the specified response body type: '${responseBodyType}'.`,
348
- e
349
- );
356
+ throwResponseBodyTypeError(response, responseBodyType, e);
350
357
  }
351
358
  }
352
359
  function decodeSyncResponseBody(response, responseBodyType) {
@@ -354,10 +361,7 @@ function decodeSyncResponseBody(response, responseBodyType) {
354
361
  return decodeReadableStreamResponseBody(response);
355
362
  } catch (e) {
356
363
  throwIfAbortError(e);
357
- throw new DataTypeError(
358
- `Response body does not conform to the specified response body type: '${responseBodyType}'.`,
359
- e
360
- );
364
+ throwResponseBodyTypeError(response, responseBodyType, e);
361
365
  }
362
366
  }
363
367
  function decodeResponseBodyImpl(response, responseBodyType) {
@@ -418,7 +422,16 @@ function getMessageFromObject(obj) {
418
422
  }
419
423
  }
420
424
  async function parseResponse(response) {
421
- const consumedBody = await response.body("text");
425
+ let consumedBody;
426
+ try {
427
+ consumedBody = await response.body("text");
428
+ } catch (e) {
429
+ const bodyError = `Response body is not available. ${e?.message ?? "Unknown error occurred."}`;
430
+ return {
431
+ message: bodyError.substring(0, 100),
432
+ body: bodyError
433
+ };
434
+ }
422
435
  try {
423
436
  const jsonBody = JSON.parse(consumedBody);
424
437
  if (typeof jsonBody === "object" && jsonBody !== null) {