@jpmorganchase/mosaic-from-http-request 0.1.0-beta.58 → 0.1.0-beta.60
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/dist/fromHttpRequest.js
CHANGED
|
@@ -2,6 +2,7 @@ import 'event-target-polyfill';
|
|
|
2
2
|
import 'yet-another-abortcontroller-polyfill';
|
|
3
3
|
import { of } from 'rxjs';
|
|
4
4
|
import { catchError, switchMap } from 'rxjs/operators';
|
|
5
|
+
import contentTypeParser from 'fast-content-type-parse';
|
|
5
6
|
import { fromFetch } from './fromFetch.js';
|
|
6
7
|
export function isErrorResponse(response) {
|
|
7
8
|
return response.error !== undefined;
|
|
@@ -14,6 +15,15 @@ export function isErrorResponse(response) {
|
|
|
14
15
|
export function fromHttpRequest(input) {
|
|
15
16
|
return fromFetch(input).pipe(switchMap(response => {
|
|
16
17
|
if (response.ok) {
|
|
18
|
+
const contentTypeHeader = response.headers.get('content-type') || '';
|
|
19
|
+
const contentType = contentTypeParser.safeParse(contentTypeHeader).type;
|
|
20
|
+
if (contentType.includes('json')) {
|
|
21
|
+
return response.json();
|
|
22
|
+
}
|
|
23
|
+
if (contentType.includes('text')) {
|
|
24
|
+
return response.text();
|
|
25
|
+
}
|
|
26
|
+
// default to json
|
|
17
27
|
return response.json();
|
|
18
28
|
}
|
|
19
29
|
return of({ error: true, message: `Error ${response.status}` });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fromHttpRequest.js","sourceRoot":"","sources":["../src/fromHttpRequest.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAC;AAC/B,OAAO,sCAAsC,CAAC;AAC9C,OAAO,EAAc,EAAE,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"fromHttpRequest.js","sourceRoot":"","sources":["../src/fromHttpRequest.ts"],"names":[],"mappings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gB,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAiB,EAAE,CAAC,CAAC;IAC5E,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jpmorganchase/mosaic-from-http-request",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.60",
|
|
4
4
|
"author": "",
|
|
5
5
|
"description": "Utility package to turn HTTP fetch requests to observables. This package can be deleted when node 18 is used.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"event-target-polyfill": "^0.0.3",
|
|
36
|
+
"fast-content-type-parse": "^1.1.0",
|
|
36
37
|
"rxjs": "^7.5.5",
|
|
37
38
|
"node-fetch": "^2.6.2",
|
|
38
39
|
"yet-another-abortcontroller-polyfill": "0.0.4"
|