-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[Discuss] Standardize API method error handling #6820
Comments
cc @parasharrajat as we kinda got sidetracked by this in a review |
Yup, I agree. This should be consistent across the codebase. I am in favor of point 3 above. |
We should also consider what to do in order to handle jsonCode:666 errors everywhere, in which our API returns a user-friendly error message that can be shown to the user. See #7229 for example. |
@marcaaron, this Monthly task hasn't been acted upon in 6 weeks; closing. If you disagree, feel encouraged to reopen it -- but pick your least important issue to close instead. |
I think we're gonna cover this is the Offline Doc but gonna let Melv close this one since we'll probably create a new GH issue eventually. |
Problem
There is a lack of consistency in how errors are handled in the codebase e.g. take the following examples:
Throwing error for handling in the catch
App/src/libs/API.js
Lines 284 to 289 in 370869f
Showing a growl
App/src/libs/actions/Policy.js
Lines 103 to 111 in 370869f
Throwing an error with no message at all
App/src/libs/actions/Policy.js
Lines 345 to 349 in 370869f
Storing the error in Onyx to show inline
App/src/libs/actions/User.js
Lines 47 to 53 in 370869f
Inconsistently checking if
jsonCode === 200
vs.jsonCode !== 200
App/src/libs/actions/Policy.js
Lines 305 to 311 in 370869f
Why is this important?
In general, keeping our code consistent makes it easier to understand, write, review, etc and will save both time and mental energy. Having a standard way to distinguish between API calls returning non 200 jsonCode and network errors means there's no question about the correct way and no discussion required.
Solution
I'm not sure yet. Let's discuss it. I think at a minimum we should decide some basic things like:
jsonCode !== 200
and notjsonCode === 200
(or vice versa)jsonCode
in the.then()
or to always handle them in the.catch()
(e.g. if we decide to handle them in the.catch()
then it might make sense to throw a non 200jsonCode
at some much lower level so we do not have to explicitly throw them)The text was updated successfully, but these errors were encountered: