-
Notifications
You must be signed in to change notification settings - Fork 30
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
Refactor getDiscussion
#10361
Refactor getDiscussion
#10361
Conversation
and safer error handling See guardian/discussion-api for type definitions Co-authored-by: Jamie B <[email protected]>
a959fb7
to
fedd1fe
Compare
Size Change: +543 B (0%) Total Size: 750 kB
ℹ️ View Unchanged
|
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.
👍 nice.
Couple of thoughts occurred to me while reading back through.
}) | ||
.catch((e) => console.error(`getDiscussion - error: ${String(e)}`)); | ||
.catch(() => { | ||
// do nothing |
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 wonder if there's a way we can still allow errors to be reported? Our getDiscussion
code could still crash, or the then
callback here could crash, and this would suppress either of those errors?
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.
Good point, we should use window.guardian.sentry.reportError
.
This could drastically increase the number of errors, though, so we’d want to do this in a separate PR
What does this change?
getDiscussion
Result
which is a discriminated union with a success and failure variantfetchJSON
which returns aResult<'ApiError' | 'NetworkError', unknown>
, and allows safely deserialising any JSON from a URLWhy?
Part of #8745
Screenshots
No change (tested locally)