Skip to content

Commit

Permalink
z_url_fetch: fix a problem where the error body was not returned (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
mworrell authored Aug 23, 2024
1 parent f603b9a commit aeea489
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/z_url_fetch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,25 @@ fetch_partial(Method, Url, Payload, Options) when is_binary(Payload), ?is_method
options = Options
},
case fetch_partial_loop(FState) of
{ok, FState1} ->
{ok, #fstate{ code = Code } = FState1} ->
FState2 = maybe_handle_content_encoding(FState1),
{ok, {
FState2#fstate.url,
FState2#fstate.headers,
FState2#fstate.length,
FState2#fstate.data
}};
if
Code >= 200 andalso Code < 300 ->
{ok, {
FState2#fstate.url,
FState2#fstate.headers,
FState2#fstate.length,
FState2#fstate.data
}};
true ->
{error, {
Code,
FState2#fstate.url,
FState2#fstate.headers,
FState2#fstate.length,
FState2#fstate.data
}}
end;
{error, _} = Error ->
Error
end.
Expand Down Expand Up @@ -566,7 +577,7 @@ maybe_redirect(#fstate{ code = Code, headers = Hs, url = Url } = FState)
{redirect, FState#fstate.method, NewUrl, FState#fstate.options}
end;
maybe_redirect(FState) ->
{error, {FState#fstate.code, FState#fstate.url}}.
{ok, FState}.

append_data(Data, <<>>, _Device) ->
{ok, Data};
Expand Down

0 comments on commit aeea489

Please sign in to comment.