@dynatrace-sdk/http-client 0.4.4 → 0.4.8
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 +31 -0
- package/cjs/index.js +22 -15
- package/docs/DOCS.md +1 -1
- package/esm/index.js +23 -15
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
@dynatrace-sdk/http-client
|
|
4
4
|
|
|
5
|
+
## 0.4.8
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- In error serializer unwrap a message from an error wrapped by the HttpSerializedError.
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
14
|
+
- @dynatrace-sdk/error-handlers@0.1.1
|
|
15
|
+
|
|
16
|
+
## 0.4.7
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
|
|
22
|
+
- @dynatrace-sdk/error-handlers@0.1.0
|
|
23
|
+
|
|
24
|
+
## 0.4.6
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Refactor error serializer registering logic.
|
|
29
|
+
|
|
30
|
+
## 0.4.5
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Remove `@dynatrace/sdk-web` dependency from `http-client`.
|
|
35
|
+
|
|
5
36
|
## 0.4.4
|
|
6
37
|
|
|
7
38
|
### Patch Changes
|
package/cjs/index.js
CHANGED
|
@@ -350,18 +350,13 @@ function decodeResponseBodyImpl(response, responseBodyType) {
|
|
|
350
350
|
switch (responseBodyType) {
|
|
351
351
|
case "buffer":
|
|
352
352
|
case "stream":
|
|
353
|
-
throw new UnsupportedOperationError(
|
|
354
|
-
`Unsupported response body type: '${responseBodyType}'`
|
|
355
|
-
);
|
|
353
|
+
throw new UnsupportedOperationError(`Unsupported response body type: '${responseBodyType}'`);
|
|
356
354
|
default:
|
|
357
355
|
throw new DataTypeError(`Invalid body type: '${responseBodyType}'`);
|
|
358
356
|
}
|
|
359
357
|
}
|
|
360
358
|
function decodeResponseBody(response, responseBodyType) {
|
|
361
|
-
return decodeResponseBodyImpl(
|
|
362
|
-
response,
|
|
363
|
-
responseBodyType
|
|
364
|
-
);
|
|
359
|
+
return decodeResponseBodyImpl(response, responseBodyType);
|
|
365
360
|
}
|
|
366
361
|
|
|
367
362
|
// packages/http-client/src/lib/platform/http-client-response.ts
|
|
@@ -391,27 +386,39 @@ var HttpClientResponse = class {
|
|
|
391
386
|
};
|
|
392
387
|
|
|
393
388
|
// packages/http-client/src/lib/platform/http-client-response-error-serializer.ts
|
|
394
|
-
var
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
389
|
+
var import_error_handlers = require("@dynatrace-sdk/error-handlers");
|
|
390
|
+
async function getMessage(response) {
|
|
391
|
+
const consumedBody = await response.body("text");
|
|
392
|
+
try {
|
|
393
|
+
const jsonBody = JSON.parse(consumedBody);
|
|
394
|
+
if (jsonBody.message && typeof jsonBody.message === "string") {
|
|
395
|
+
return jsonBody.message;
|
|
396
|
+
}
|
|
397
|
+
} catch (e) {
|
|
398
|
+
return consumedBody.substring(0, 100);
|
|
400
399
|
}
|
|
400
|
+
return consumedBody.substring(0, 100);
|
|
401
401
|
}
|
|
402
402
|
var httpClientResponseErrorSerializer = async (error) => {
|
|
403
403
|
if (error instanceof HttpClientResponseError) {
|
|
404
404
|
const status = error.response.status;
|
|
405
|
-
const message = await error.response
|
|
405
|
+
const message = await getMessage(error.response);
|
|
406
406
|
return {
|
|
407
407
|
name: error.name,
|
|
408
408
|
status,
|
|
409
409
|
message,
|
|
410
410
|
stack: error.stack,
|
|
411
|
-
type:
|
|
411
|
+
type: import_error_handlers.ErrorType.HTTP
|
|
412
412
|
};
|
|
413
413
|
}
|
|
414
414
|
};
|
|
415
|
+
var errorSerializerAdded = false;
|
|
416
|
+
function addHttpClientResponseErrorSerializer() {
|
|
417
|
+
if (!errorSerializerAdded && (0, import_error_handlers.isGlobalErrorSerializerSupported)()) {
|
|
418
|
+
errorSerializerAdded = true;
|
|
419
|
+
(0, import_error_handlers.addGlobalErrorSerializer)(httpClientResponseErrorSerializer);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
415
422
|
|
|
416
423
|
// packages/http-client/src/lib/platform/http-client-response-error.ts
|
|
417
424
|
var HttpClientResponseError = class extends BaseError {
|
package/docs/DOCS.md
CHANGED
package/esm/index.js
CHANGED
|
@@ -313,18 +313,13 @@ function decodeResponseBodyImpl(response, responseBodyType) {
|
|
|
313
313
|
switch (responseBodyType) {
|
|
314
314
|
case "buffer":
|
|
315
315
|
case "stream":
|
|
316
|
-
throw new UnsupportedOperationError(
|
|
317
|
-
`Unsupported response body type: '${responseBodyType}'`
|
|
318
|
-
);
|
|
316
|
+
throw new UnsupportedOperationError(`Unsupported response body type: '${responseBodyType}'`);
|
|
319
317
|
default:
|
|
320
318
|
throw new DataTypeError(`Invalid body type: '${responseBodyType}'`);
|
|
321
319
|
}
|
|
322
320
|
}
|
|
323
321
|
function decodeResponseBody(response, responseBodyType) {
|
|
324
|
-
return decodeResponseBodyImpl(
|
|
325
|
-
response,
|
|
326
|
-
responseBodyType
|
|
327
|
-
);
|
|
322
|
+
return decodeResponseBodyImpl(response, responseBodyType);
|
|
328
323
|
}
|
|
329
324
|
|
|
330
325
|
// packages/http-client/src/lib/platform/http-client-response.ts
|
|
@@ -356,19 +351,25 @@ var HttpClientResponse = class {
|
|
|
356
351
|
// packages/http-client/src/lib/platform/http-client-response-error-serializer.ts
|
|
357
352
|
import {
|
|
358
353
|
addGlobalErrorSerializer,
|
|
359
|
-
ErrorType
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
function
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
354
|
+
ErrorType,
|
|
355
|
+
isGlobalErrorSerializerSupported
|
|
356
|
+
} from "@dynatrace-sdk/error-handlers";
|
|
357
|
+
async function getMessage(response) {
|
|
358
|
+
const consumedBody = await response.body("text");
|
|
359
|
+
try {
|
|
360
|
+
const jsonBody = JSON.parse(consumedBody);
|
|
361
|
+
if (jsonBody.message && typeof jsonBody.message === "string") {
|
|
362
|
+
return jsonBody.message;
|
|
363
|
+
}
|
|
364
|
+
} catch (e) {
|
|
365
|
+
return consumedBody.substring(0, 100);
|
|
366
366
|
}
|
|
367
|
+
return consumedBody.substring(0, 100);
|
|
367
368
|
}
|
|
368
369
|
var httpClientResponseErrorSerializer = async (error) => {
|
|
369
370
|
if (error instanceof HttpClientResponseError) {
|
|
370
371
|
const status = error.response.status;
|
|
371
|
-
const message = await error.response
|
|
372
|
+
const message = await getMessage(error.response);
|
|
372
373
|
return {
|
|
373
374
|
name: error.name,
|
|
374
375
|
status,
|
|
@@ -378,6 +379,13 @@ var httpClientResponseErrorSerializer = async (error) => {
|
|
|
378
379
|
};
|
|
379
380
|
}
|
|
380
381
|
};
|
|
382
|
+
var errorSerializerAdded = false;
|
|
383
|
+
function addHttpClientResponseErrorSerializer() {
|
|
384
|
+
if (!errorSerializerAdded && isGlobalErrorSerializerSupported()) {
|
|
385
|
+
errorSerializerAdded = true;
|
|
386
|
+
addGlobalErrorSerializer(httpClientResponseErrorSerializer);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
381
389
|
|
|
382
390
|
// packages/http-client/src/lib/platform/http-client-response-error.ts
|
|
383
391
|
var HttpClientResponseError = class extends BaseError {
|
package/package.json
CHANGED