Skip to content

Commit

Permalink
CMS-545: Add retry to fetch advisories on park operating dates page (#…
Browse files Browse the repository at this point in the history
…1546)

* CMS-545: Add retry to fecth advisories on park operating dates page

* CMS-545: Add small fix
  • Loading branch information
ayumi-oxd authored Dec 10, 2024
1 parent 59b5ae3 commit cdc45a0
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/gatsby/src/pages/plan-your-trip/park-operating-dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,34 @@ const ParkLink = ({ park, apiBaseUrl }) => {
}
}

// get advisories
useEffect(() => {
const fetchAdvisoriesWithRetry = (retries = 3, delay = 1000) => {
setIsLoadingAdvisories(true)
loadAdvisories(apiBaseUrl, park.orcs)
.then(response => {
setAdvisories(response.data.data)
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()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [apiBaseUrl, park.orcs])

if (!addedSeasonalAdvisory) {
Expand Down

0 comments on commit cdc45a0

Please sign in to comment.