Skip to content

Commit 5a23422

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 1913f00 commit 5a23422

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
@@ -14,6 +14,7 @@ import { formatFiatString } from '../../hooks/useFiatText'
1414
import { useHandler } from '../../hooks/useHandler'
1515
import { formatDate } from '../../locales/intl'
1616
import { lstrings } from '../../locales/strings'
17+
import { snooze } from '../../util/utils'
1718
import { MinimalButton } from '../buttons/MinimalButton'
1819
import { FillLoader } from '../progress-indicators/FillLoader'
1920
import { Theme, useTheme } from '../services/ThemeContext'
@@ -213,8 +214,11 @@ const SwipeChartComponent = (params: Props) => {
213214
// Rate limit error, use our API key as a fallback
214215
if (!fetchUrl.includes('x_cg_pro_api_key') && ENV.COINGECKO_API_KEY !== '') {
215216
fetchUrl = `${COINGECKO_URL_PRO}${fetchPath}&x_cg_pro_api_key=${ENV.COINGECKO_API_KEY}`
216-
continue
217217
}
218+
// Wait 2 second before retrying. It typically takes 1 minute
219+
// before rate limiting is relieved, so even 2 seconds is hasty.
220+
await snooze(2000)
221+
continue
218222
}
219223
throw new Error(`Failed to fetch market data: ${apiError.status.error_code} ${apiError.status.error_message}`)
220224
}

0 commit comments

Comments
 (0)