MCPcopy Index your code
hub / github.com/apache/pouchdb / fetchJSON

Function fetchJSON

lib/index.js:6864–6901  ·  view source on GitHub ↗
(url, options)

Source from the content-addressed store, hash-verified

6862 }
6863
6864 async function fetchJSON(url, options) {
6865
6866 const result = {};
6867
6868 options = options || {};
6869 options.headers = options.headers || new nodeFetch.Headers();
6870
6871 if (!options.headers.get('Content-Type')) {
6872 options.headers.set('Content-Type', 'application/json');
6873 }
6874 if (!options.headers.get('Accept')) {
6875 options.headers.set('Accept', 'application/json');
6876 }
6877
6878 const response = await ourFetch(url, options);
6879 result.ok = response.ok;
6880 result.status = response.status;
6881 const json = await response.json();
6882
6883 result.data = json;
6884 if (!result.ok) {
6885 result.data.status = result.status;
6886 const err = generateErrorFromResponse(result.data);
6887 throw err;
6888 }
6889
6890 if (Array.isArray(result.data)) {
6891 result.data = result.data.map(function (v) {
6892 if (v.error || v.missing) {
6893 return generateErrorFromResponse(v);
6894 } else {
6895 return v;
6896 }
6897 });
6898 }
6899
6900 return result;
6901 }
6902
6903 let setupPromise;
6904

Callers 4

setupFunction · 0.70
HttpPouchFunction · 0.70
doBulkGetFunction · 0.70
fetchDataFunction · 0.70

Calls 3

ourFetchFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…