Skip to content

Commit 2f34dc7

Browse files
committed
Never fail on rate limiting
Do or do not, there is not try-catch – Yoda Failure is not an option – Ed Harris
1 parent 89f8bbd commit 2f34dc7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/components/charts/SwipeChart.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useHandler } from '../../hooks/useHandler'
1515
import { formatDate } from '../../locales/intl'
1616
import { lstrings } from '../../locales/strings'
1717
import { fixSides, mapSides, sidesToMargin } from '../../util/sides'
18+
import { snooze } from '../../util/utils'
1819
import { MinimalButton } from '../buttons/MinimalButton'
1920
import { FillLoader } from '../progress-indicators/FillLoader'
2021
import { Theme, useTheme } from '../services/ThemeContext'
@@ -219,8 +220,11 @@ const SwipeChartComponent = (params: Props) => {
219220
// Rate limit error, use our API key as a fallback
220221
if (!fetchUrl.includes('x_cg_pro_api_key') && ENV.COINGECKO_API_KEY !== '') {
221222
fetchUrl = `${COINGECKO_URL_PRO}${fetchPath}&x_cg_pro_api_key=${ENV.COINGECKO_API_KEY}`
222-
continue
223223
}
224+
// Wait 2 second before retrying. It typically takes 1 minute
225+
// before rate limiting is relieved, so even 2 seconds is hasty.
226+
await snooze(2000)
227+
continue
224228
}
225229
throw new Error(`Failed to fetch market data: ${apiError.status.error_code} ${apiError.status.error_message}`)
226230
}

0 commit comments

Comments
 (0)