-
-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle api 404 error to display data properly #1802
fix: handle api 404 error to display data properly #1802
Conversation
log.error(err.message); | ||
throw err; | ||
log.error('Error in getCaptures:', err.message); | ||
return []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yunchipang why you disable the throwing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because if it throws an error, getCaptures()
will not return anything, then captures
in static props gets undefined, and the entire top page just shows 404.
for now, to inform the error i'm just logging it. would you like this to be handled in some other way? my purpose is to have some props display on the page even when some other props were not populated properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, let's merge your code first, and we can continue, we can back to this if there are some problem.
BTW, I also don't like the try-catch way to handle error, I prefer to use Promise function to do it:
promise
.then(goodHandler)
.catch(badHandler)
log.error(err.message); | ||
throw err; | ||
log.error('Error in getCaptures:', err.message); | ||
return []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, let's merge your code first, and we can continue, we can back to this if there are some problem.
BTW, I also don't like the try-catch way to handle error, I prefer to use Promise function to do it:
promise
.then(goodHandler)
.catch(badHandler)
@yunchipang thanks for you contribution! |
Description
Fixes #1801
⛔️ Cause: when populating static props (captures, countries, growers, organizations, wallets) in
top.js
, if any of the 5 items got a 404 upon API request, the page renders a 404 not found because the field was not properly populated.🧩 Solution: consolidate all API request functions into
src/models/api.js
, including error handling. When an API request failed, the function returns an empty array.📝 Note: For now, API requests to
captures
andgrowers
return 404, so the below error persists, and the frontend is only displayingcountries
,organizations
, andwallets
(please refer to the screenshot in the next section). I believe the investigation should continue on treetracker-query-api in terms of fetching captures and featured growers. I've checked/captures
and/growers/featured
endpoints, neither of them are working.Type of change
Screenshots
How Has This Been Tested?
Checklist: