From 2e76d2a6763260401c4ad168f3eb4f8416573fce Mon Sep 17 00:00:00 2001 From: Adelyn Breedlove Date: Tue, 29 Jan 2019 17:18:49 -0700 Subject: Better shard shutdown and HTTP error logging --- bin/bot.ml | 2 +- lib/dune | 2 +- lib/http.ml | 4 +++- lib/sharder.ml | 2 ++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bin/bot.ml b/bin/bot.ml index 0a832ea..f22c363 100644 --- a/bin/bot.ml +++ b/bin/bot.ml @@ -85,7 +85,7 @@ let main () = | Some t -> t | None -> failwith "No token in env" in - Client.start ~compress:true token + Client.start token >>> fun c -> Ivar.fill client c diff --git a/lib/dune b/lib/dune index 7fa316e..cf0ff7e 100644 --- a/lib/dune +++ b/lib/dune @@ -20,7 +20,7 @@ event_models client client_options disml dispatch endpoints event http impl opcode rl s sharder ) - (libraries checkseum.c core async_ssl cohttp-async decompress logs yojson websocket-async ppx_deriving_yojson.runtime) + (libraries checkseum.ocaml core async_ssl cohttp-async decompress logs yojson websocket-async ppx_deriving_yojson.runtime) (preprocess (pps ppx_sexp_conv ppx_deriving_yojson)) ) diff --git a/lib/http.ml b/lib/http.ml index 5e49843..283ab69 100644 --- a/lib/http.ml +++ b/lib/http.ml @@ -33,9 +33,11 @@ module Base = struct | None -> return ()) >>= fun () -> match resp |> Response.status |> Code.code_of_status with - | 200 -> body |> Cohttp_async.Body.to_string >>| Yojson.Safe.from_string >>= Deferred.Or_error.return + | code when Code.is_success code -> body |> Cohttp_async.Body.to_string >>| Yojson.Safe.from_string >>= Deferred.Or_error.return | code -> body |> Cohttp_async.Body.to_string >>= fun body -> + let headers = Response.sexp_of_t resp |> Sexp.to_string_hum in + Logs.warn (fun m -> m "[Unsuccessful Response] [Code: %d]\n%s\n%s" code body headers); Deferred.Or_error.errorf "Unsuccessful response received: %d - %s" code body let request ?(body=`Null) ?(query=[]) m path = diff --git a/lib/sharder.ml b/lib/sharder.ml index 157967d..d4e6bd1 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -279,6 +279,8 @@ module Shard = struct let shutdown_clean shard = let (_,w) = shard._internal in + Pipe.write (snd shard.pipe) (Frame.create ~opcode:(Frame.Opcode.Close) ~final:true ()) + >>= fun _ -> Ivar.fill shard.hb_stopper (); Writer.close w -- cgit v1.2.3