Skip to content

Commit 6253e37

Browse files
committedOct 10, 2024·
fix: history/status endpoints
1 parent 267a573 commit 6253e37

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed
 

‎src/imandra_http_api_client.ml

+15-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ let read (dec : 'a Decoders_yojson.Basic.Decode.decoder) (resp, body) :
6161
in
6262
Lwt.return res
6363

64+
let read_string (resp, body) : ('a, [> error ]) Lwt_result.t =
65+
let open Lwt.Syntax in
66+
let* body = Cohttp_lwt.Body.to_string body in
67+
let status = Cohttp.Response.status resp in
68+
let res =
69+
if status = `OK then
70+
Ok body
71+
else
72+
read_error body
73+
|> CCResult.flat_map (fun err -> Error (`Error_response (status, err)))
74+
in
75+
Lwt.return res
76+
6477
let eval (c : Config.t) req =
6578
let open Lwt.Syntax in
6679
let uri = build_uri c "/eval/by-src" in
@@ -74,14 +87,14 @@ let get_history (c : Config.t) =
7487
let uri = build_uri c "/history" in
7588
let headers = default_headers c |> Cohttp.Header.of_list in
7689
let* res = Cohttp_lwt_unix.Client.call `GET uri ~headers in
77-
read Decoders_yojson.Basic.Decode.string res
90+
read_string res
7891

7992
let get_status (c : Config.t) =
8093
let open Lwt.Syntax in
8194
let uri = build_uri c "/status" in
8295
let headers = default_headers c |> Cohttp.Header.of_list in
8396
let* res = Cohttp_lwt_unix.Client.call `GET uri ~headers in
84-
read Decoders_yojson.Basic.Decode.string res
97+
read_string res
8598

8699
let instance_by_name (c : Config.t) req =
87100
let open Lwt.Syntax in

‎src/imandra_http_api_client.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ val eval :
171171
(Api.Response.eval_result Api.Response.with_capture, [> error ]) result Lwt.t
172172

173173
val get_history :
174-
Config.t -> (string Api.Response.with_capture, [> error ]) result Lwt.t
174+
Config.t -> (string, [> error ]) result Lwt.t
175175

176176
val get_status :
177-
Config.t -> (string Api.Response.with_capture, [> error ]) result Lwt.t
177+
Config.t -> (string, [> error ]) result Lwt.t
178178

179179
val instance_by_name :
180180
Config.t ->

0 commit comments

Comments
 (0)
Please sign in to comment.