Skip to content

Commit

Permalink
[Finch] Change error handling, fix for response stream (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
hodak committed Apr 11, 2024
1 parent 76c7ede commit e693721
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/tesla/adapter/finch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ if Code.ensure_loaded?(Finch) do
{:ok, %Finch.Response{status: status, headers: headers, body: body}} ->
{:ok, %Tesla.Env{env | status: status, headers: headers, body: body}}

{:error, mint_error} ->
{:error, Exception.message(mint_error)}
{:error, %Mint.TransportError{reason: reason}} ->
{:error, reason}

{:error, reason} ->
{:error, reason}
end
end

Expand Down
18 changes: 18 additions & 0 deletions test/tesla/adapter/finch_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,22 @@ defmodule Tesla.Adapter.FinchTest do
start_supervised!({Finch, opts})
:ok
end

test "Delay request" do
request = %Env{
method: :head,
url: "#{@http}/delay/1"
}

assert {:error, :timeout} = call(request, receive_timeout: 100)
end

test "Delay request with stream" do
request = %Env{
method: :head,
url: "#{@http}/delay/1"
}

assert {:error, :timeout} = call(request, receive_timeout: 100, response: :stream)
end
end

0 comments on commit e693721

Please sign in to comment.