Skip to content

Commit

Permalink
Prepare for Finch 0.20
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmach committed Nov 25, 2024
1 parent a9d713a commit 520bdfe
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions lib/req/finch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,34 @@ defmodule Req.Finch do
acc = collector.(acc, :done)
{req, %{resp | body: acc}}

# TODO: call collector.(:halt) once {:error, error, acc} is
# returned on Finch v0.20
# TODO: remove when we require Finch 0.20
{:error, exception} ->
{req, normalize_error(exception)}

{:error, %Mint.TransportError{reason: reason}} ->
{req, %Req.TransportError{reason: reason}}
{:error, exception, {{acc, collector}, _req, _resp}} ->
collector.(acc, :halt)
{req, normalize_error(exception)}
end
end

{:error, %Mint.HTTPError{module: Mint.HTTP1, reason: reason}} ->
{req, %Req.HTTPError{protocol: :http1, reason: reason}}
defp normalize_error(%Mint.TransportError{reason: reason}) do
%Req.TransportError{reason: reason}
end

{:error, %Mint.HTTPError{module: Mint.HTTP2, reason: reason}} ->
{req, %Req.HTTPError{protocol: :http2, reason: reason}}
defp normalize_error(%Mint.HTTPError{module: Mint.HTTP1, reason: reason}) do
%Req.HTTPError{protocol: :http1, reason: reason}
end

{:error, %Finch.Error{reason: reason}} ->
{req, %Req.HTTPError{protocol: :http2, reason: reason}}
defp normalize_error(%Mint.HTTPError{module: Mint.HTTP2, reason: reason}) do
%Req.HTTPError{protocol: :http2, reason: reason}
end

{:error, exception} ->
{req, exception}
end
defp normalize_error(%Finch.Error{reason: reason}) do
%Req.HTTPError{protocol: :http2, reason: reason}
end

defp normalize_error(error) do
error
end

defp finch_stream_into_legacy_self(req, finch_req, finch_name, finch_options) do
Expand Down

0 comments on commit 520bdfe

Please sign in to comment.