Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/exit retry loop when 404 or 429 #3626

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/composables/queries/useHistoricalPricesQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,21 @@ export default function useHistoricalPricesQuery(
*/
const aggregateBy = shapshotDaysNum <= 90 ? 'hour' : 'day';

return await coingeckoService.prices.getTokensHistorical(
tokensList,
shapshotDaysNum,
1,
aggregateBy
);
// if the coingecko query fails for this query key, we can pretty safely assume it'll keep failing
// by returning an empty object we signal to stop retrying this hook.
try {
const historicalPrices =
await coingeckoService.prices.getTokensHistorical(
tokensList,
shapshotDaysNum,
1,
aggregateBy
);

return historicalPrices;
} catch {
return {};
}
};

const queryOptions = reactive({
Expand Down
8 changes: 7 additions & 1 deletion src/lib/utils/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ export async function retryPromiseWithDelay<T>(
try {
return await promise;
} catch (e) {
if (retryCount === 1) {
const responseStatusCode = (e as any)?.response?.status || 0;

if (
retryCount === 1 ||
responseStatusCode === 404 ||
responseStatusCode === 429
) {
return Promise.reject(e);
}
console.log('retrying promise', retryCount, 'time');
Expand Down