(url, retries = 3, delay = 2000)
| 1 | import axios from 'axios'; |
| 2 | async function fetchWithRetries(url, retries = 3, delay = 2000) { |
| 3 | let attempt = 0; |
| 4 | while (attempt < retries) { |
| 5 | try { |
| 6 | const { data } = await axios.get(url); |
| 7 | return data; |
| 8 | } |
| 9 | catch (err) { |
| 10 | attempt++; |
| 11 | console.error(`[WHY] Attempt ${attempt} failed:`, err.message); |
| 12 | if (attempt >= retries) |
| 13 | throw new Error('Max retries reached'); |
| 14 | await new Promise(r => setTimeout(r, delay)); |
| 15 | } |
| 16 | } |
| 17 | } |
| 18 | export default { |
| 19 | command: 'why', |
| 20 | aliases: ['whyme', 'question'], |