From f790382fd814b826b3d5306c85155b43039899a1 Mon Sep 17 00:00:00 2001 From: "dimitris.mostrous" Date: Sun, 27 Mar 2022 12:47:29 +0100 Subject: [PATCH] Add @mbacarella's check for complete absence of grpc-status --- lib/grpc-async/client.ml | 6 +++++- lib/grpc-lwt/client.ml | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/grpc-async/client.ml b/lib/grpc-async/client.ml index 7cfec72..5791000 100644 --- a/lib/grpc-async/client.ml +++ b/lib/grpc-async/client.ml @@ -67,7 +67,11 @@ let call ~service ~rpc ?(scheme = "https") ~handler ~do_request Ivar.fill handler_res_ivar handler_res; return ()); let%bind out = Ivar.read out_ivar in - let%bind trailers_status = Ivar.read trailers_status_ivar in + let%bind trailers_status = + (* In case no grpc-status appears in headers or trailers. *) + if Ivar.is_full trailers_status_ivar then Ivar.read trailers_status_ivar + else return (Grpc.Status.v ~message:"Server did not return grpc-status" Grpc.Status.Unknown) + in match out with | Error _ as e -> return e | Ok out -> return (Ok (out, trailers_status)) diff --git a/lib/grpc-lwt/client.ml b/lib/grpc-lwt/client.ml index 44d5582..54e8377 100644 --- a/lib/grpc-lwt/client.ml +++ b/lib/grpc-lwt/client.ml @@ -64,7 +64,12 @@ let call ~service ~rpc ?(scheme = "https") ~handler ~do_request let+ handler_res = handler write_body read_body in Lwt.wakeup_later handler_res_notify handler_res); let* out in - let+ status in + let+ status = + match Lwt.state status with + (* In case no grpc-status appears in headers or trailers. *) + | Sleep -> let+ status in status + | _ -> Lwt.return @@ Grpc.Status.v ~message:"Server did not return grpc-status" Grpc.Status.Unknown + in match out with Error _ as e -> e | Ok out -> Ok (out, status) module Rpc = struct