@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/esm/index.js CHANGED
@@ -289,6 +289,14 @@ async function decodeBlobResponseBody(response) {
289
289
  function decodeReadableStreamResponseBody(response) {
290
290
  return response.body !== null ? response.body : emptyReadableStream();
291
291
  }
292
+ function throwResponseBodyTypeError(response, responseBodyType, cause) {
293
+ throw new DataTypeError(
294
+ `Response body does not conform to the specified response body type: '${responseBodyType}'. The content type of the response is '${response.headers.get(
295
+ "Content-Type"
296
+ )}'.`,
297
+ cause
298
+ );
299
+ }
292
300
  async function decodeAsyncResponseBody(response, responseBodyType) {
293
301
  try {
294
302
  switch (responseBodyType) {
@@ -307,10 +315,7 @@ async function decodeAsyncResponseBody(response, responseBodyType) {
307
315
  }
308
316
  } catch (e) {
309
317
  throwIfAbortError(e);
310
- throw new DataTypeError(
311
- `Response body does not conform to the specified response body type: '${responseBodyType}'.`,
312
- e
313
- );
318
+ throwResponseBodyTypeError(response, responseBodyType, e);
314
319
  }
315
320
  }
316
321
  function decodeSyncResponseBody(response, responseBodyType) {
@@ -318,10 +323,7 @@ function decodeSyncResponseBody(response, responseBodyType) {
318
323
  return decodeReadableStreamResponseBody(response);
319
324
  } catch (e) {
320
325
  throwIfAbortError(e);
321
- throw new DataTypeError(
322
- `Response body does not conform to the specified response body type: '${responseBodyType}'.`,
323
- e
324
- );
326
+ throwResponseBodyTypeError(response, responseBodyType, e);
325
327
  }
326
328
  }
327
329
  function decodeResponseBodyImpl(response, responseBodyType) {
@@ -386,7 +388,16 @@ function getMessageFromObject(obj) {
386
388
  }
387
389
  }
388
390
  async function parseResponse(response) {
389
- const consumedBody = await response.body("text");
391
+ let consumedBody;
392
+ try {
393
+ consumedBody = await response.body("text");
394
+ } catch (e) {
395
+ const bodyError = `Response body is not available. ${e?.message ?? "Unknown error occurred."}`;
396
+ return {
397
+ message: bodyError.substring(0, 100),
398
+ body: bodyError
399
+ };
400
+ }
390
401
  try {
391
402
  const jsonBody = JSON.parse(consumedBody);
392
403
  if (typeof jsonBody === "object" && jsonBody !== null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynatrace-sdk/http-client",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "license": "Apache-2.0",
5
5
  "dependencies": {
6
6
  "@dynatrace-sdk/error-handlers": "^1.1.0"
@@ -1,5 +0,0 @@
1
- {
2
- "docs": {
3
- "title": "http-client"
4
- }
5
- }