@rest-vir/define-service 0.11.3 → 0.11.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.
|
@@ -2,6 +2,7 @@ import { check } from '@augment-vir/assert';
|
|
|
2
2
|
import { addPrefix, filterMap, getObjectTypedEntries, HttpMethod, } from '@augment-vir/common';
|
|
3
3
|
import { assertValidShape } from 'object-shape-tester';
|
|
4
4
|
import { buildUrl } from 'url-vir';
|
|
5
|
+
import { parseJsonWithUndefined } from '../augments/json.js';
|
|
5
6
|
function defaultFetch(...[url, requestInit,]) {
|
|
6
7
|
return fetch(url, requestInit);
|
|
7
8
|
}
|
|
@@ -64,7 +65,9 @@ export async function fetchEndpoint(endpoint, ...params) {
|
|
|
64
65
|
/* node:coverage ignore next: all tests mock fetch so we're never going to have a fallback here. */
|
|
65
66
|
const response = await (fetch || defaultFetch)(url, requestInit, endpoint);
|
|
66
67
|
if (response.ok) {
|
|
67
|
-
const responseData = endpoint.responseDataShape
|
|
68
|
+
const responseData = endpoint.responseDataShape
|
|
69
|
+
? parseJsonWithUndefined(await response.text())
|
|
70
|
+
: undefined;
|
|
68
71
|
if (endpoint.responseDataShape) {
|
|
69
72
|
assertValidShape(responseData, endpoint.responseDataShape, { allowExtraKeys: true });
|
|
70
73
|
}
|