aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdelyn Breedlove <[email protected]>2019-01-29 17:18:49 -0700
committerAdelyn Breedlove <[email protected]>2019-01-29 17:18:49 -0700
commit2e76d2a6763260401c4ad168f3eb4f8416573fce (patch)
tree5061bf3c65f11dfb8e6b55772f10f99ee0dbd2bf
parentRemove some silly internals (diff)
downloaddisml-2e76d2a6763260401c4ad168f3eb4f8416573fce.tar.xz
disml-2e76d2a6763260401c4ad168f3eb4f8416573fce.zip
Better shard shutdown and HTTP error logging
-rw-r--r--bin/bot.ml2
-rw-r--r--lib/dune2
-rw-r--r--lib/http.ml4
-rw-r--r--lib/sharder.ml2
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