MCPcopy
hub / github.com/apache/pouchdb / fetchJSON

Function fetchJSON

lib/index.es.js:6859–6896  ·  view source on GitHub ↗
(url, options)

Source from the content-addressed store, hash-verified

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

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…