Added custom let* for handlers.

The error page is now displayed for any intermediate error.

Commit
59b321967f83385296c9ce92fb29ee7f6c8b75db
Author
Marius Peter <marius.peter@tutanota.com>
Author date
Committer
Marius Peter <marius.peter@tutanota.com>
Committer date
lib/handlers.ml
index f4a7d7b0..95aecd32 100644..100644
@@ -1,16 +1,25 @@
1 Removed: open Lwt.Syntax
1 Added: let ( let* ) m f =
2 Added: let open Lwt.Infix in
3 Added: m >>= function
4 Added: | Ok x -> f x
5 Added: | Error e ->
6 Added: let msg = Format.asprintf "%a" Git_unix.Store.pp_error e in
7 Added: Views.error_page msg |> Dream_html.respond
2 8
3 9 let ogit_root _req = Views.ogit_root () |> Dream_html.respond
4 10
5 11 let repo_summary req =
6 12 let repo_path = Dream.param req "repo_name" in
7 Removed: let* branches = Git_helpers.all_branches repo_path
8 Removed: and* commits = Git_helpers.latest_commits repo_path 10 in
9 Removed: match (branches, commits) with
10 Removed: | Ok branches, Ok commits ->
11 Removed: Views.repo_summary repo_path ~branches ~commits |> Dream_html.respond
12 Removed: | Error msg, _ | _, Error msg -> Views.error_page msg |> Dream_html.respond
13 Added: let branches = [ "bing"; "bong" ] in
14 Added: let* commits = Git_helpers.recent_commits repo_path 10 in
15 Added: Views.repo_summary repo_path branches commits |> Dream_html.respond
13 16
17 Added: let repo_commit req =
18 Added: let repo_path = Dream.param req "repo_name" in
19 Added: let id = match Dream.query req "id" with Some id -> id | None -> "" in
20 Added: let* commit = Git_helpers.get_commit repo_path id in
21 Added: Views.repo_commit repo_path commit |> Dream_html.respond
22 Added:
14 23 (* let repo_tree req = *)
15 24 (* let repo_name = Dream.param req "repo_name" in *)
16 25 (* let path = Git_helpers.full_path repo_name in *)
@@ -29,6 +38,7 @@
29 38 Dream.scope "/:repo_name" []
30 39 [
31 40 Dream.get "/" repo_summary;
41 Added: Dream.get "/commit/" repo_commit;
32 42 (* Dream.get "/tree" repo_tree; *)
33 43 (* Dream.get "/blob" repo_blob; *)
34 44 ];