MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / runner

Method runner

static/js/utils.js:320–402  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

318 }
319
320 const runner = async () => {
321 for (let attempt = 0; attempt <= retryCount; attempt += 1) {
322 let timedOut = false;
323 let timeoutId = null;
324 const controller = new AbortController();
325
326 if (requestKey && cancelPrevious) {
327 const previousController = this.inflightRequests.get(requestKey);
328 if (previousController) {
329 previousController.__cancelReason = 'request_replaced';
330 previousController.abort();
331 }
332 }
333 if (requestKey) {
334 this.inflightRequests.set(requestKey, controller);
335 }
336
337 if (externalSignal) {
338 if (externalSignal.aborted) {
339 controller.abort();
340 } else {
341 externalSignal.addEventListener('abort', () => controller.abort(), { once: true });
342 }
343 }
344
345 if (effectiveTimeoutMs > 0) {
346 timeoutId = setTimeout(() => {
347 timedOut = true;
348 controller.__cancelReason = 'timeout';
349 controller.abort();
350 }, effectiveTimeoutMs);
351 }
352
353 try {
354 if (!this.networkOnline && requestPriority === 'low') {
355 const offlineError = new Error('网络离线,后台请求已跳过');
356 offlineError.name = 'NetworkOfflineError';
357 throw offlineError;
358 }
359
360 const response = await fetch(url, { ...finalOptions, signal: controller.signal });
361 const data = await response.json().catch(() => ({}));
362
363 if (!response.ok) {
364 const error = new Error(data.detail || `HTTP ${response.status}`);
365 error.response = response;
366 error.data = data;
367 throw error;
368 }
369
370 return data;
371 } catch (error) {
372 const isAbortError = error?.name === 'AbortError';
373 const cancelReason = controller.__cancelReason || '';
374 const isExpectedAbort = isAbortError && (cancelReason === 'request_replaced' || externalSignal?.aborted);
375 const isTimeoutError = isAbortError && (timedOut || cancelReason === 'timeout');
376 const isOfflineError = error?.name === 'NetworkOfflineError';
377 const isNetworkError = !error.response && !isAbortError && !isOfflineError;

Callers

nothing calls this directly

Calls 5

sleepMethod · 0.95
notifyNetworkStateMethod · 0.95
getMethod · 0.45
jsonMethod · 0.45

Tested by

no test coverage detected