2021-03-24 20:34:40 +03:00
..
2021-03-24 19:11:23 +03:00
2021-03-24 17:33:35 +03:00
2021-03-24 17:33:35 +03:00
2021-03-24 17:33:35 +03:00

Insert the Dream.catch middleware to have it handle all errors and exceptions in one place:

let () =
  Dream.run
  @@ Dream.logger
  @@ Dream.catch ~debug:true
  @@ Dream.router [

    Dream.get "/"
      (fun _ ->
        Dream.respond "Good morning, world!");

    Dream.get "/bad"
      (fun _ ->
        Dream.respond ~status:`Bad_request "");

    Dream.get "/fail"
      (fun _ ->
        raise (Failure "The web app had a fail!"));

  ]
  @@ fun _ ->
    Dream.respond ~status:`Not_found ""

Where to go from here?

  • 5-catch handles errors from all your handlers in one place.