MCPcopy
hub / github.com/ampproject/amphtml / fetch_

Method fetch_

testing/helpers/service.js:212–233  ·  view source on GitHub ↗
(url, action, timeout = 10000)

Source from the content-addressed store, hash-verified

210 }
211
212 static fetch_(url, action, timeout = 10000) {
213 const xhr = fetch(url).then((response) => {
214 const {ok, status, statusText} = response;
215 if (!ok) {
216 throw new Error(
217 `RequestBank.${action}: HTTP ${status} error -- ${statusText}`
218 );
219 }
220 return response;
221 });
222 if (timeout <= 0) {
223 return xhr;
224 }
225 const timer = new Promise((_, reject) => {
226 setTimeout(() => {
227 reject(
228 new Error(`"RequestBank.${action}" timed out after ${timeout} ms.`)
229 );
230 }, timeout);
231 });
232 return Promise.race([xhr, timer]);
233 }
234}
235
236export class BrowserController {

Callers 2

withdrawMethod · 0.45
tearDownMethod · 0.45

Calls 2

fetchFunction · 0.85
thenMethod · 0.45

Tested by

no test coverage detected