mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-09 12:23:32 -04:00
do not decode result of http post
This commit is contained in:
parent
12b5f6c765
commit
50743d3097
1 changed files with 11 additions and 5 deletions
|
|
@ -68,7 +68,7 @@ module Httpc : sig
|
||||||
val send :
|
val send :
|
||||||
t ->
|
t ->
|
||||||
path:string ->
|
path:string ->
|
||||||
decode:(Pbrt.Decoder.t -> 'a) ->
|
decode:[ `Dec of Pbrt.Decoder.t -> 'a | `Ret of 'a ] ->
|
||||||
string ->
|
string ->
|
||||||
('a, error) result
|
('a, error) result
|
||||||
|
|
||||||
|
|
@ -122,11 +122,17 @@ end = struct
|
||||||
let code = Curl.get_responsecode curl in
|
let code = Curl.get_responsecode curl in
|
||||||
if !debug_ then
|
if !debug_ then
|
||||||
Printf.eprintf "result body: %S\n%!" (Buffer.contents buf_res);
|
Printf.eprintf "result body: %S\n%!" (Buffer.contents buf_res);
|
||||||
let dec = Pbrt.Decoder.of_string (Buffer.contents buf_res) in
|
|
||||||
if code >= 200 && code < 300 then (
|
if code >= 200 && code < 300 then (
|
||||||
let res = decode dec in
|
match decode with
|
||||||
Ok res
|
| `Ret x -> Ok x
|
||||||
|
| `Dec f ->
|
||||||
|
let dec = Pbrt.Decoder.of_string (Buffer.contents buf_res) in
|
||||||
|
(try Ok (f dec)
|
||||||
|
with e ->
|
||||||
|
Error
|
||||||
|
(`Failure ("decoding failed with:\n" ^ Printexc.to_string e)))
|
||||||
) else (
|
) else (
|
||||||
|
let dec = Pbrt.Decoder.of_string (Buffer.contents buf_res) in
|
||||||
let status = Status.decode_status dec in
|
let status = Status.decode_status dec in
|
||||||
Error (`Status (code, status))
|
Error (`Status (code, status))
|
||||||
)
|
)
|
||||||
|
|
@ -304,7 +310,7 @@ let mk_emitter ~stop ~(config : Config.t) () : (module EMITTER) =
|
||||||
Pbrt.Encoder.reset encoder;
|
Pbrt.Encoder.reset encoder;
|
||||||
encode x encoder;
|
encode x encoder;
|
||||||
let data = Pbrt.Encoder.to_string encoder in
|
let data = Pbrt.Encoder.to_string encoder in
|
||||||
match Httpc.send httpc ~path ~decode:(fun _ -> ()) data with
|
match Httpc.send httpc ~path ~decode:(`Ret ()) data with
|
||||||
| Ok () -> ()
|
| Ok () -> ()
|
||||||
| Error `Sysbreak ->
|
| Error `Sysbreak ->
|
||||||
Printf.eprintf "ctrl-c captured, stopping\n%!";
|
Printf.eprintf "ctrl-c captured, stopping\n%!";
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue