streams: Display error if stream update fails.#5289
streams: Display error if stream update fails.#5289Fingel wants to merge 1 commit intozulip:mainfrom
Conversation
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.
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.
Should we also preemptively add a try/catch and show a toast here?
There was a problem hiding this comment.
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