Skip to content

Promise.catch example #904

Closed
Closed
@nojaf

Description

@nojaf

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.

let f = async () => {
  Exn.raiseError("Hi!")
}
f()
->Promise.catch(async exn => {
  switch exn {
  | Exn.Error(exn) => exn->Exn.message->Option.getOr("yow")
  | _ => "no error"
  }
})
->Promise.done

Like, what else is there to catch if exn is not Exn.Error?

Would like to contribute a good example after receiving some guidance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions