diff options
| author | Adelyn Breelove <[email protected]> | 2018-12-17 16:09:35 -0700 |
|---|---|---|
| committer | Adelyn Breelove <[email protected]> | 2018-12-17 16:09:35 -0700 |
| commit | 792c8c437f45d9fd2529f1ccab27faf79d98ba91 (patch) | |
| tree | 3c8f5e59d617219a3d442083c29d5cbdfa6ffdb5 /lib/http.ml | |
| parent | More stuff (diff) | |
| download | disml-792c8c437f45d9fd2529f1ccab27faf79d98ba91.tar.xz disml-792c8c437f45d9fd2529f1ccab27faf79d98ba91.zip | |
Some refactoring of http code
Diffstat (limited to 'lib/http.ml')
| -rw-r--r-- | lib/http.ml | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/http.ml b/lib/http.ml index abc2b28..e2e5471 100644 --- a/lib/http.ml +++ b/lib/http.ml @@ -34,7 +34,12 @@ module Make(T : S.Token) = struct | Some r -> Mvar.put (Rl.find_exn !rl path) r | None -> raise Bad_response_headers) >>= fun () -> - body |> Cohttp_async.Body.to_string >>| Yojson.Safe.from_string + match resp |> Response.status |> Code.code_of_status with + | 200 -> body |> Cohttp_async.Body.to_string >>= Deferred.Or_error.return + | code -> + body |> Cohttp_async.Body.to_string >>= fun body -> + Deferred.Or_error.errorf "Unsuccessful response received: %d - %s" code body + let request ?(body=`Null) m path = rl := Rl.update ~f:(function |