MCPcopy Create free account
hub / github.com/chokcoco/iCSS / fetchWithRetry

Method fetchWithRetry

website/app/lib/github.ts:308–328  ·  view source on GitHub ↗
(url: string, options: RequestInit, retries: number = 3)

Source from the content-addressed store, hash-verified

306
307 // 带重试的 fetch 函数
308 private static async fetchWithRetry(url: string, options: RequestInit, retries: number = 3): Promise<Response> {
309 for (let i = 0; i < retries; i++) {
310 try {
311 const response = await fetch(url, options);
312 if (response.ok || response.status === 403) {
313 return response;
314 }
315 // 如果不是 403 错误,等待后重试
316 if (i < retries - 1) {
317 await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1))); // 递增延迟
318 }
319 } catch (error) {
320 console.error(`Fetch attempt ${i + 1} failed:`, error);
321 if (i === retries - 1) {
322 throw error;
323 }
324 await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1)));
325 }
326 }
327 throw new Error(`Failed after ${retries} retries`);
328 }
329}

Callers 2

getIssuesMethod · 0.95
getIssueMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected