-
Notifications
You must be signed in to change notification settings - Fork 6
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: Added error handling when fetch users api call fails #2179
Conversation
@theofficialnar How does this fix the reported error? The error that we are seeing is indicating that a promise was rejected, but instead of an Error object, which is the standard practice, an object with the keys _meta, data, error, and status was provided. Which tells me its not really a unhandled rejection error but a handled one that is reading something unexpected |
@agalin920 right, I realize the promise is throwing the |
@theofficialnar yea I agree. Just pointing out a potentially deeper issue |
@agalin920 I found out that It's probably worth mentioning that I am not 100% sure why If it is by design that 4** responses should not be thrown as errors in |
src/utility/request.js
Outdated
@@ -75,6 +75,11 @@ export function request(url, opts = {}) { | |||
|
|||
// if (res.status === 422) {} | |||
|
|||
// Client error | |||
if (res.status >= 400 && res.status < 500) { |
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.
We can't really do this since this would break existing functionality that expects 400s to go into .then
Some actions will check for data int .then and default to an empty [] or {};
This will cause the .then not to go in and default.
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.
Gotcha, I guess that answers my question as to why request.js
doesn't throw errors for 400s then. I'll just handle that inside fetchUsers()
then.
@theofficialnar Looking at this call trace It looks like the culprit is a 403 when fetching the instance If we take a look at the code for the instance fetch
We can see that on 403 it is throwing the response but the response is not an Error Object so if there is a subsequent catch I would expect the error mentioned in the sentry ticket And as predicted there is a catch on its chain
so I expect these type of cases to be the reason for the error |
@agalin920 I see, right I'll add some handling for that as well. There is an event under this similar sentry issue that doesn't have a 403 on /instances though, and only 403d on /domains and /users. Since domains isn't throwing the response on 403 but /users does, don't you think it's also worth handling that (which is what I currently have added on the changes)? https://zestyio.sentry.io/issues/2277454417/events/a32f854cc9cd4e69a4e66ab13b68efed/ |
Yes it also needs to be handled on /users just keep in mind that the issue is NOT an unhandled catch. It is the throw res.
|
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.
That's it. Thanks
Added a catch when api call fails
Closes #2103