@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/esm/index.js CHANGED
@@ -289,6 +289,16 @@ 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
+ )}'. Response status is '${response.status}'. Response source is '${response.headers.get(
297
+ "dynatrace-response-source"
298
+ )}'`,
299
+ cause
300
+ );
301
+ }
292
302
  async function decodeAsyncResponseBody(response, responseBodyType) {
293
303
  try {
294
304
  switch (responseBodyType) {
@@ -307,10 +317,7 @@ async function decodeAsyncResponseBody(response, responseBodyType) {
307
317
  }
308
318
  } catch (e) {
309
319
  throwIfAbortError(e);
310
- throw new DataTypeError(
311
- `Response body does not conform to the specified response body type: '${responseBodyType}'.`,
312
- e
313
- );
320
+ throwResponseBodyTypeError(response, responseBodyType, e);
314
321
  }
315
322
  }
316
323
  function decodeSyncResponseBody(response, responseBodyType) {
@@ -318,10 +325,7 @@ function decodeSyncResponseBody(response, responseBodyType) {
318
325
  return decodeReadableStreamResponseBody(response);
319
326
  } catch (e) {
320
327
  throwIfAbortError(e);
321
- throw new DataTypeError(
322
- `Response body does not conform to the specified response body type: '${responseBodyType}'.`,
323
- e
324
- );
328
+ throwResponseBodyTypeError(response, responseBodyType, e);
325
329
  }
326
330
  }
327
331
  function decodeResponseBodyImpl(response, responseBodyType) {
@@ -386,7 +390,16 @@ function getMessageFromObject(obj) {
386
390
  }
387
391
  }
388
392
  async function parseResponse(response) {
389
- const consumedBody = await response.body("text");
393
+ let consumedBody;
394
+ try {
395
+ consumedBody = await response.body("text");
396
+ } catch (e) {
397
+ const bodyError = `Response body is not available. ${e?.message ?? "Unknown error occurred."}`;
398
+ return {
399
+ message: bodyError.substring(0, 100),
400
+ body: bodyError
401
+ };
402
+ }
390
403
  try {
391
404
  const jsonBody = JSON.parse(consumedBody);
392
405
  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.5",
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
- }