From e0c7c4c369e272d44efb7cc3a05e27979c817b88 Mon Sep 17 00:00:00 2001 From: Luis Azedo Date: Thu, 5 Jan 2017 12:40:20 +0000 Subject: [PATCH] =?UTF-8?q?ensure=20get=20body=20doesn=E2=80=99t=20crash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/couchbeam_httpc.erl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/couchbeam_httpc.erl b/src/couchbeam_httpc.erl index 260cb643..0c9b9455 100644 --- a/src/couchbeam_httpc.erl +++ b/src/couchbeam_httpc.erl @@ -103,13 +103,16 @@ db_resp({ok, _, _, _}=Resp, []) -> db_resp({ok, Status, Headers, Ref}=Resp, Expect) -> case lists:member(Status, Expect) of true -> Resp; - false -> - {ok, Body} = hackney:body(Ref), - {error, {bad_response, {Status, Headers, Body}}} + false -> {error, {bad_response, {Status, Headers, db_resp_body(Ref)}}} end; db_resp(Error, _Expect) -> Error. +db_resp_body(Ref) -> + case hackney:body(Ref) of + {ok, Body} -> Body; + _ -> <<>> + end. %% @doc Asemble the server URL for the given client %% @spec server_url({Host, Port}) -> iolist()