Skip to content

Commit 30c3a29

Browse files
authored
Merge pull request #577 from carrascoacd/acc/fix-log-level
Ensure connection errors return the expected error tuple
2 parents 04a94e6 + 122d8bc commit 30c3a29

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

lib/tesla/adapter/mint.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,15 @@ if Code.ensure_loaded?(Mint.HTTP) do
176176
end
177177
end
178178

179-
defp make_request(conn, method, path, headers, body),
180-
do: HTTP.request(conn, method, path, headers, body)
179+
defp make_request(conn, method, path, headers, body) do
180+
case HTTP.request(conn, method, path, headers, body) do
181+
{:ok, conn, ref} ->
182+
{:ok, conn, ref}
183+
184+
{:error, _conn, error} ->
185+
{:error, error}
186+
end
187+
end
181188

182189
defp stream_request(conn, ref, fun) do
183190
case next_chunk(fun) do

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule Tesla.Mixfile do
22
use Mix.Project
33

44
@source_url "https://github.com/teamon/tesla"
5-
@version "1.6.0"
5+
@version "1.6.1"
66

77
def project do
88
[

test/tesla/adapter/mint_test.exs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule Tesla.Adapter.MintTest do
1111
cacertfile: Path.join([to_string(:code.priv_dir(:httparrot)), "/ssl/server-ca.crt"])
1212
]
1313

14-
test "Delay request" do
14+
test "timeout request" do
1515
request = %Env{
1616
method: :head,
1717
url: "#{@http}/delay/1"
@@ -179,6 +179,26 @@ defmodule Tesla.Adapter.MintTest do
179179
assert conn.state == :closed
180180
end
181181

182+
test "body_as :plain - returns error tuple matching the specification when connection is closed",
183+
%{conn: conn, original: original} do
184+
request = %Env{
185+
method: :get,
186+
url: "#{@http}/stream-bytes/10"
187+
}
188+
189+
assert {:ok, %Env{} = response} =
190+
call(request, conn: conn, original: original, close_conn: false)
191+
192+
assert response.status == 200
193+
assert byte_size(response.body) == 16
194+
195+
{:ok, conn} = Tesla.Adapter.Mint.close(conn)
196+
assert conn.state == :closed
197+
198+
assert {:error, %Mint.HTTPError{reason: :closed, module: Mint.HTTP1}} =
199+
call(request, conn: conn, original: original, close_conn: false)
200+
end
201+
182202
test "body_as :stream", %{conn: conn, original: original} do
183203
request = %Env{
184204
method: :get,

0 commit comments

Comments
 (0)