From 6253e37b2d2baa52246173166e1f020a6d6ca9cb Mon Sep 17 00:00:00 2001 From: Nicola Mometto Date: Thu, 10 Oct 2024 14:44:32 +0100 Subject: [PATCH] fix: history/status endpoints --- src/imandra_http_api_client.ml | 17 +++++++++++++++-- src/imandra_http_api_client.mli | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/imandra_http_api_client.ml b/src/imandra_http_api_client.ml index 26ef241..0e9d93e 100644 --- a/src/imandra_http_api_client.ml +++ b/src/imandra_http_api_client.ml @@ -61,6 +61,19 @@ let read (dec : 'a Decoders_yojson.Basic.Decode.decoder) (resp, body) : in Lwt.return res +let read_string (resp, body) : ('a, [> error ]) Lwt_result.t = + let open Lwt.Syntax in + let* body = Cohttp_lwt.Body.to_string body in + let status = Cohttp.Response.status resp in + let res = + if status = `OK then + Ok body + else + read_error body + |> CCResult.flat_map (fun err -> Error (`Error_response (status, err))) + in + Lwt.return res + let eval (c : Config.t) req = let open Lwt.Syntax in let uri = build_uri c "/eval/by-src" in @@ -74,14 +87,14 @@ let get_history (c : Config.t) = let uri = build_uri c "/history" in let headers = default_headers c |> Cohttp.Header.of_list in let* res = Cohttp_lwt_unix.Client.call `GET uri ~headers in - read Decoders_yojson.Basic.Decode.string res + read_string res let get_status (c : Config.t) = let open Lwt.Syntax in let uri = build_uri c "/status" in let headers = default_headers c |> Cohttp.Header.of_list in let* res = Cohttp_lwt_unix.Client.call `GET uri ~headers in - read Decoders_yojson.Basic.Decode.string res + read_string res let instance_by_name (c : Config.t) req = let open Lwt.Syntax in diff --git a/src/imandra_http_api_client.mli b/src/imandra_http_api_client.mli index 4cc8e2c..e94a040 100644 --- a/src/imandra_http_api_client.mli +++ b/src/imandra_http_api_client.mli @@ -171,10 +171,10 @@ val eval : (Api.Response.eval_result Api.Response.with_capture, [> error ]) result Lwt.t val get_history : - Config.t -> (string Api.Response.with_capture, [> error ]) result Lwt.t + Config.t -> (string, [> error ]) result Lwt.t val get_status : - Config.t -> (string Api.Response.with_capture, [> error ]) result Lwt.t + Config.t -> (string, [> error ]) result Lwt.t val instance_by_name : Config.t ->