From 23ba8ed20a0c621bbe0f83b0c23622ed644ebf64 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 5 Jul 2023 11:38:19 +0800 Subject: [PATCH 1/2] Exit the retry loop when you get 404 or 429 status codes --- src/lib/utils/promise.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/utils/promise.ts b/src/lib/utils/promise.ts index 38bc4b0daf..9eda56e870 100644 --- a/src/lib/utils/promise.ts +++ b/src/lib/utils/promise.ts @@ -8,7 +8,13 @@ export async function retryPromiseWithDelay( 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'); From b03671b166e7e931d16ffd6f915a6ef7c6b46223 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 5 Jul 2023 11:40:48 +0800 Subject: [PATCH 2/2] Return an empty object to prevent multiple failed attempts --- .../queries/useHistoricalPricesQuery.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/composables/queries/useHistoricalPricesQuery.ts b/src/composables/queries/useHistoricalPricesQuery.ts index ca6e5b6887..21e540a3ec 100644 --- a/src/composables/queries/useHistoricalPricesQuery.ts +++ b/src/composables/queries/useHistoricalPricesQuery.ts @@ -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({