Skip to content

Commit

Permalink
Attempt to handle closed streams
Browse files Browse the repository at this point in the history
What does this commit/MR/PR do?

- Attempt to handle closed streams

Why is this commit/MR/PR needed?

- A closed stream interrupts the type determination,
attempt to capture the error early into a Fastimage.Error{}
  • Loading branch information
stephenmoloney committed Oct 4, 2018
1 parent 4a609ee commit b76e875
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/fastimage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ defmodule Fastimage do
else
{:error, {:closed, :timeout}} = reason ->
Error.exception(reason)

{:error, %Error{} = error} ->
{:error, error}
end
end

Expand Down
7 changes: 7 additions & 0 deletions lib/fastimage/stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ defmodule Fastimage.Stream do
| stream_ref: stream_ref,
stream_state: :processing
})
else
{:error, {:closed, :timeout}} ->
reason = {:connection_closed_after_stream_timeout, acc}
{:error, Error.exception(reason)}

other ->
other
end
end

Expand Down
4 changes: 0 additions & 4 deletions test/fastimage_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ defmodule FastimageTest do
assert list_results == list_expected_results(n)
end

test "403 on remote file request returns error tuple" do
assert {:error, %Fastimage.Error{}} = Fastimage.type("http://httpstat.us/403")
end

# private

defp assert_size_and_type(input, expected_size, expected_type) do
Expand Down

0 comments on commit b76e875

Please sign in to comment.