From 9b48acd6dc6cfa38a5c72240767309c49a539670 Mon Sep 17 00:00:00 2001 From: Ayumi Tanaka Date: Mon, 9 Dec 2024 15:30:57 -0800 Subject: [PATCH 1/2] CMS-545: Add retry to fecth advisories on park operating dates page --- .../plan-your-trip/park-operating-dates.js | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/gatsby/src/pages/plan-your-trip/park-operating-dates.js b/src/gatsby/src/pages/plan-your-trip/park-operating-dates.js index c0768b08d..827fa9a92 100644 --- a/src/gatsby/src/pages/plan-your-trip/park-operating-dates.js +++ b/src/gatsby/src/pages/plan-your-trip/park-operating-dates.js @@ -60,8 +60,7 @@ const ParkLink = ({ park, apiBaseUrl }) => { } } - // get advisories - useEffect(() => { + const fetchAdvisoriesWithRetry = (retries = 3, delay = 1000) => { setIsLoadingAdvisories(true) loadAdvisories(apiBaseUrl, park.orcs) .then(response => { @@ -69,13 +68,25 @@ const ParkLink = ({ park, apiBaseUrl }) => { setAdvisoryLoadError(false) }) .catch(error => { - setAdvisories([]) - setAdvisoryLoadError(true) - console.error("Error fetching advisories:", error) + if (error.response && error.response.status === 429 && retries > 0) { + // retry with exponential backoff + setTimeout(() => { + fetchAdvisoriesWithRetry(retries - 1, delay * 2) + }, delay) + } else { + setAdvisories([]) + setAdvisoryLoadError(true) + console.error("Error fetching advisories:", error) + } }) .finally(() => { setIsLoadingAdvisories(false) }) + } + + // get advisories + useEffect(() => { + fetchAdvisoriesWithRetry() }, [apiBaseUrl, park.orcs]) if (!addedSeasonalAdvisory) { From b4024abf33c31fe15d94f96e50699cd070dd606f Mon Sep 17 00:00:00 2001 From: Ayumi Tanaka Date: Mon, 9 Dec 2024 15:52:28 -0800 Subject: [PATCH 2/2] CMS-545: Add small fix --- src/gatsby/src/pages/plan-your-trip/park-operating-dates.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gatsby/src/pages/plan-your-trip/park-operating-dates.js b/src/gatsby/src/pages/plan-your-trip/park-operating-dates.js index 827fa9a92..33cdaa470 100644 --- a/src/gatsby/src/pages/plan-your-trip/park-operating-dates.js +++ b/src/gatsby/src/pages/plan-your-trip/park-operating-dates.js @@ -87,6 +87,7 @@ const ParkLink = ({ park, apiBaseUrl }) => { // get advisories useEffect(() => { fetchAdvisoriesWithRetry() + // eslint-disable-next-line react-hooks/exhaustive-deps }, [apiBaseUrl, park.orcs]) if (!addedSeasonalAdvisory) {