MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / withRetry

Function withRetry

cosplay/cosplay.ts:62–80  ·  view source on GitHub ↗
(
  fn: () => Promise<T>,
  retries: number = CONFIG.MAX_RETRIES
)

Source from the content-addressed store, hash-verified

60}
61
62async function withRetry<T>(
63 fn: () => Promise<T>,
64 retries: number = CONFIG.MAX_RETRIES
65): Promise<T> {
66 let lastError: unknown;
67 for (let attempt = 1; attempt <= retries; attempt++) {
68 try {
69 return await fn();
70 } catch (error) {
71 lastError = error;
72 if (classifyError(error) === "permanent" || attempt === retries) {
73 throw error;
74 }
75 const delay = CONFIG.RETRY_BASE_DELAY * Math.pow(2, attempt - 1);
76 await new Promise((resolve) => setTimeout(resolve, delay));
77 }
78 }
79 throw lastError;
80}
81
82class CosplayScraper {
83 private readonly client: AxiosInstance;

Callers 3

fetchImageUrlsMethod · 0.85
getRandomPhotoSetMethod · 0.85
downloadImageMethod · 0.85

Calls 2

fnFunction · 0.85
classifyErrorFunction · 0.85

Tested by

no test coverage detected