-
-
Notifications
You must be signed in to change notification settings - Fork 246
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
Promise.catch example #904
Comments
There is an example for About what's there to catch, you could also throw ReScript exceptions somewhere deeper in the corresponding function. Some are even built-in. |
Thanks, this is interesting! So
|
The |
Hmm, I guess the try/catch way does have most appeal. How would this look like in an event listener? // You can't make `async ev` because the handler would no longer fit
let onSubmit = ev => {
somePromiseFn(blah)
->Promise.done
}
<form onSubmit={onSubmit}>...</form> |
But I have a helper function for more complex cases: // PromiseUtils.res
let run = (makePromise: unit => promise<unit>) => makePromise()->Promise.done // Other file
let onSubmit = ev => PromiseUtils.run(async () =>
switch await someResultPromise() {
| Ok(_data) => ()
| Error(error) =>
logError(error)
showReadableErrorToUser(error)
}
)
<form onSubmit={onSubmit}>...</form> Also, most of my promises use result and not exceptions. But I am not sure if this helper should be added to Core.Promise |
Hi @fhammerschmidt,
https://rescript-lang.org/docs/manual/latest/promise is lacking a good sample on how to deal with
Promise.catch
blocks.It is still a bit unclear to me what
exn
is. (Notice that I don't go to its definition in the IDE)And how to unwrap
exn
to something useful. This works, but I'm not sure if it is idiomatic or not.Like, what else is there to catch if
exn
is notExn.Error
?Would like to contribute a good example after receiving some guidance.
The text was updated successfully, but these errors were encountered: