Skip to content

Commit 3375e96

Browse files
committed
Build without lwt_ppx
1 parent eae7465 commit 3375e96

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

main_mirage/unikernel.ml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,23 @@ module Fetch = struct
2525

2626
let fetch ~ctx url =
2727
Logs.info (fun fmt -> fmt "Fetching %a" Uri.pp url);
28-
match%lwt get ~ctx url with
29-
| exception Failure msg ->
30-
Lwt.return (Error (`System msg))
31-
| exception Unix.Unix_error (_, msg, _) ->
32-
Lwt.return (Error (`System msg))
33-
| exception _ ->
34-
Lwt.return (Error (`Unknown))
35-
| { status = `OK; _ }, body ->
36-
let%lwt body = Cohttp_lwt.Body.to_string body in
37-
Lwt.return (Ok body)
38-
| { status; _ }, _ ->
39-
let code = Cohttp.Code.code_of_status status in
40-
Lwt.return (Error (`Http code))
28+
let get () =
29+
get ~ctx url >>= function
30+
| { Cohttp.Response.status = `OK; _ }, body ->
31+
Cohttp_lwt.Body.to_string body >>= fun body ->
32+
Lwt.return (Ok body)
33+
| { Cohttp.Response.status; _ }, _ ->
34+
let code = Cohttp.Code.code_of_status status in
35+
Lwt.return (Error (`Http code))
36+
in
37+
Lwt.catch get (function
38+
| Failure msg ->
39+
Lwt.return (Error (`System msg))
40+
| Unix.Unix_error (_, msg, _) ->
41+
Lwt.return (Error (`System msg))
42+
| _ ->
43+
Lwt.return (Error (`Unknown))
44+
)
4145

4246
(** at most 5 fetch at once *)
4347
let fetch ~ctx = pooled 5 (fetch ~ctx)

0 commit comments

Comments
 (0)