-
Notifications
You must be signed in to change notification settings - Fork 288
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
Handle fetch top-level errors #618
Handle fetch top-level errors #618
Conversation
@valeriangalliat is attempting to deploy a commit to the Gladly Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@valeriangalliat Thanks for the PR! The try/catch behavior makes sense and would be good to merge. Could you break that into its own PR? I don't think we should add
|
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.
Please break out the try/catch changes into its own PR, excluding the addition of fetch-retry.
That makes sense! I like the idea of the |
e43259f
to
8fb6693
Compare
@kmjennison updated! This PR now only includes catching of fetch errors |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## v1.x #618 +/- ##
=======================================
Coverage 99.25% 99.25%
=======================================
Files 30 30
Lines 673 675 +2
Branches 223 223
=======================================
+ Hits 668 670 +2
Misses 5 5
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
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.
LGTM. Thank you!
Diff best viewed in ignore whitespaces mode.
Handle fetch top-level errors
This PR wraps the
await fetch
calls to login and logout API endpoints by atry/catch
block so that we callonLoginRequestError
andonLogoutRequestError
not-only in case of HTTP errors, but also in case of network errors (e.g.fetch
rejecting withTypeError: failed to fetch
), instead of leaving those unhandled.Retry network errorsMoved to its own PR
Also in order to mitigate network errors, this PR introduces a retry logic when calling the login and logout API endpoints, provided by fetch-retry.
This module defaults to retrying up to 3 times at 1s intervals, and only retrying network errors (the case where
fetch
rejects, as opposed to HTTP errors where it resolves withresponse.ok = false
).I think those defaults are sensible, and I added a configuration option
fetchRetryConfig
to allow fine tuning the retry logic if needed.I think the rate of fetch network errors I'm seeing on login API calls is exacerbated by the fact the login API is called on every page (#424 - I tried coming up with a solution for that too but didn't find a reliable way to do that just yet), nevertheless this PR shouldn't leave those errors unhandled, and thanks to the retry logic, should lower their frequency.
Let me know what you think and if you need me to make any edits!