I hope I didn’t screw something up, but it looks like
This
let handleError = (express: t) => {
express->useError((err, _req, res, _next) => {
let uuid = randomUUID()
// switch err {
// | Js.Exn.Error(obj) => Console.log4(uuid, Exn.name(obj), Exn.message(obj), Exn.stack(obj))
// | _ => Console.log3(uuid, "rescript exn mystery meat", err)
// }
try {
raise(err)
} catch {
| Js.Exn.Error(obj) => Console.log4(uuid, Exn.name(obj), Exn.message(obj), Exn.stack(obj))
| _ => Console.log3(uuid, "rescript exn mystery meat", err)
}
res->json({"error-logged": uuid})
})
}
does
[backend:dev] 7a6ed568-0b88-4333-a75a-657f5b9b64d1 Error Validation error, password is None, {"email":"me@example.com","passwordXXXXX":"the password"} Error: Validation error, password is None, {"email":"me@example.com","passwordXXXXX":"the password"}
flipping the commented code to
let handleError = (express: t) => {
express->useError((err, _req, res, _next) => {
let uuid = randomUUID()
switch err {
| Js.Exn.Error(obj) => Console.log4(uuid, Exn.name(obj), Exn.message(obj), Exn.stack(obj))
| _ => Console.log3(uuid, "rescript exn mystery meat", err)
}
// try {
// raise(err)
// } catch {
// | Js.Exn.Error(obj) => Console.log4(uuid, Exn.name(obj), Exn.message(obj), Exn.stack(obj))
// | _ => Console.log3(uuid, "rescript exn mystery meat", err)
// }
res->json({"error-logged": uuid})
})
}
does
[backend:dev] 2111fccb-94e5-43b4-b3f0-b0645868f15c rescript exn mystery meat Error: Validation error, password is None, {"email":"me@example.com","passwordXXXXX":"the password"}
looks like just switching on err doesn’t match Js.Exn.Error unless you reraise it first.
Doesn’t a try/catch in rescript have some secrete sauce syntax, like “exception” in the sample below?
switch list{1, 2, 3}->List.getExn(4) {
| item => Js.log(item)
| exception Not_found => Js.log("No such item found!")
}