MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / fetchJSON

Function fetchJSON

Support/SingleFileLibs/javascript/app.js:140–158  ·  view source on GitHub ↗
(url, opts = {})

Source from the content-addressed store, hash-verified

138 }
139
140 async function fetchJSON(url, opts = {}) {
141 const res = await fetch(url, { headers: { ...authHeaders() }, ...opts });
142 if (!res.ok) {
143 let message = `HTTP ${res.status} for ${url}`;
144 let bodyText = '';
145 try { bodyText = await res.text(); } catch {}
146 let payload;
147 try { payload = JSON.parse(bodyText); } catch { payload = null; }
148 const payloadMsg = payload && payload.message ? payload.message : '';
149 if (res.status === 403 && (payloadMsg.toLowerCase().includes('rate limit') || (res.headers.get('x-ratelimit-remaining') === '0'))) {
150 throw new Error(buildRateLimitMessage(res, payloadMsg));
151 }
152 if (res.status === 401) {
153 throw new Error('GitHub API authentication failed. Please check your token.');
154 }
155 throw new Error(message + (payloadMsg ? ` — ${payloadMsg}` : ''));
156 }
157 return res.json();
158 }
159
160 async function fetchText(url, opts = {}) {
161 const res = await fetch(url, opts);

Callers 5

getRepoMetaFunction · 0.85
getReleasesFunction · 0.85
getCommitShaForRefFunction · 0.85
getRepoTreeFunction · 0.85
loadDependenciesJsonFunction · 0.85

Calls 4

authHeadersFunction · 0.85
buildRateLimitMessageFunction · 0.85
parseMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected