Skip to content

Commit

Permalink
Merge pull request #31 from concord-consortium/186340805-get-data-qa-…
Browse files Browse the repository at this point in the history
…issues

Fix fetch errors. (PT-186340805)
  • Loading branch information
lublagg authored Feb 22, 2024
2 parents ba66606 + eb374e2 commit e6d487a
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 e6d487a

Please sign in to comment.