Skip to content

Commit

Permalink
Fix fetch errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
lublagg committed Feb 20, 2024
1 parent b4fd782 commit eb374e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/constants/regionData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
},
{
Expand Down
14 changes: 7 additions & 7 deletions src/scripts/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit eb374e2

Please sign in to comment.