Skip to content

Commit

Permalink
ensure get body doesn’t crash
Browse files Browse the repository at this point in the history
  • Loading branch information
lazedo committed Jan 5, 2017
1 parent a4565cf commit e0c7c4c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/couchbeam_httpc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e0c7c4c

Please sign in to comment.