MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / apiCallWithRetry

Function apiCallWithRetry

plugins/terabox.js:13–39  ·  view source on GitHub ↗
(url, maxRetries = 3, baseDelay = 2000)

Source from the content-addressed store, hash-verified

11 const chatId = context.chatId || message.key.remoteJid;
12 const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));
13 const apiCallWithRetry = async (url, maxRetries = 3, baseDelay = 2000) => {
14 for (let attempt = 1; attempt <= maxRetries; attempt++) {
15 try {
16 await wait(1000);
17 const response = await axios.get(url, {
18 timeout: 60000,
19 headers: { 'User-Agent': 'Mozilla/5.0' }
20 });
21 return response;
22 }
23 catch (error) {
24 const isRateLimited = error.response?.status === 429 ||
25 error.code === 'ECONNABORTED' ||
26 error.code === 'ETIMEDOUT';
27 if (attempt === maxRetries)
28 throw error;
29 if (isRateLimited) {
30 const delay = baseDelay * Math.pow(2, attempt - 1);
31 console.log(`Retrying in ${delay}ms... (${attempt}/${maxRetries})`);
32 await wait(delay);
33 }
34 else {
35 throw error;
36 }
37 }
38 }
39 };
40 const downloadFileWithProgress = async (url, filepath, maxRetries = 3) => {
41 for (let attempt = 1; attempt <= maxRetries; attempt++) {
42 try {

Callers 1

handlerFunction · 0.85

Calls 1

waitFunction · 0.70

Tested by

no test coverage detected