-
-
Notifications
You must be signed in to change notification settings - Fork 655
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
streams: Display error if stream update fails. #5289
base: main
Are you sure you want to change the base?
Conversation
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.
Thanks! One comment.
src/streams/EditStreamScreen.js
Outdated
dispatch( | ||
updateExistingStream(stream.stream_id, stream, { name, description, isPrivate }), | ||
).catch(error => { | ||
showToast(error.message); | ||
}); |
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.
Instead of the Promise#catch
method, use async/await and a try/catch.
There's a good thread somewhere explaining why, with examples from Anders too. I'll try to locate that and put an entry in the style guide.
3c8c792
to
13c2da8
Compare
Displays a toast containing an error string if a call to updateExistingStream returns a failed promise. Fixes: zulip#5286
13c2da8
to
5e0387a
Compare
(name: string, description: string, isPrivate: boolean) => { | ||
api.createStream(auth, name, description, [ownEmail], isPrivate); | ||
async (name: string, description: string, isPrivate: boolean) => { | ||
await api.createStream(auth, name, description, [ownEmail], isPrivate); |
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.
Should we also preemptively add a try/catch and show a toast 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.
Yeah, good thought -- let's handle this the same way.
@gnprice Does this look better? Admittedly I'm still kinda wrapping my head around what is going on here with the dispatch hook/async/ and promises. |
It does! To note here what I said on our call this afternoon: while we're waiting for the request, let's show some UI feedback that things are happening: make the button disabled (both visually, and in the sense of not accepting a second press) and perhaps showing a spinner or something. Ah, which we can do with the A smaller thing: in the case of failure, a modal alert is probably better than a toast. Then on dismissing the alert, stay on the same screen. That way if there's some way they can tweak the details and retry, they can do that without re-entering the other details. See |
Displays a toast containing an error string if a call to
updateExistingStream returns a failed promise.
Fixes: #5286