From eb374e253124062248a01195d0c5fc190fb8e313 Mon Sep 17 00:00:00 2001 From: lublagg Date: Tue, 20 Feb 2024 09:34:08 -0800 Subject: [PATCH] Fix fetch errors. --- src/constants/regionData.ts | 4 ++-- src/scripts/api.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/constants/regionData.ts b/src/constants/regionData.ts index 4a5317c..1a30cef 100644 --- a/src/constants/regionData.ts +++ b/src/constants/regionData.ts @@ -33,11 +33,11 @@ export const multiRegions: IRegion[] = [ "States": ["Minnesota", "Wisconsin", "Michigan"] }, { - "Region": "Cornbelt I", + "Region": "Corn Belt I", "States": ["Illinois", "Indiana", "Ohio"] }, { - "Region": "Cornbelt II", + "Region": "Corn Belt II", "States": ["Iowa", "Missouri"] }, { diff --git a/src/scripts/api.ts b/src/scripts/api.ts index d8a3f98..b69339a 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -444,18 +444,18 @@ const getAttrData = async (params: IGetAttrDataParams, selectedOptions: IStateOp export const fetchDataWithRetry = async (req: string, setReqCount: ISetReqCount, maxRetries = 3,) => { let retries = 0; while (retries < maxRetries) { - const response = await fetchJsonp(req, { timeout: 10000 }); // Increase the timeout - if (response?.ok) { + try { + const response = await fetchJsonp(req, { timeout: 10000 }); // Increase the timeout const json = await response.json(); setReqCount((prevState) => { const completed = prevState.completed + 1 > prevState.total ? prevState.total : prevState.completed + 1; return {...prevState, completed}; - }); + }); return json; - } else { - // eslint-disable-next-line no-console - console.log(`Request attempt ${retries + 1} failed:`, req); - retries++; + } catch (error) { + // eslint-disable-next-line no-console + console.log("Error fetching data:", error); + retries++; } } return undefined;