From 4541e48f22aac7d3073d14bedc9aad69a092a375 Mon Sep 17 00:00:00 2001 From: Ryan Kavanagh Date: Fri, 12 Jun 2020 22:36:10 -0400 Subject: Better error handling --- bin/leda.ml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/leda.ml b/bin/leda.ml index 98e6244..c32f3a5 100644 --- a/bin/leda.ml +++ b/bin/leda.ml @@ -16,7 +16,7 @@ module R = Gemini.GeminiTransaction.GeminiTransaction(T)(Gemini.TlsUtils.TlsUtil let () = Lwt_main.run begin let%lwt () = Mirage_crypto_rng_lwt.initialize () in - let request : (R.request, string) Base.Result.t = R.make_request (Sys.get_argv()).(1) in + let request = R.make_request (Sys.get_argv()).(1) in let rec loop t = match%lwt Lwt_stream.next (Term.events t) with | `Key _ -> Lwt.return () @@ -44,8 +44,18 @@ let () = let%lwt () = Term.image t (h <-> c) in let%lwt () = Term.refresh t in loop t - | Error m -> + | Error R.TOO_MANY_REDIRECTS -> let%lwt () = Term.release t in - Lwt_io.printl m) - | Error m -> Lwt_io.printl m + Lwt_io.printl "Too many redirects" + | Error (R.X_DOMAIN_REDIR _) -> + let%lwt () = Term.release t in + Lwt_io.printl ("Attempted to redirect across domains") + | Error (UNKNOWN_RESPONSE s) -> + let%lwt () = Term.release t in + Lwt_io.printl ("Unknown response: " ^ s) + | Error (MISC s) -> + let%lwt () = Term.release t in + Lwt_io.printl ("Error: " ^ s)) + | Error m -> + Lwt_io.printl m end -- cgit v1.2.3