Skip to content

Commit

Permalink
Don't fail when API endpoint returns 500
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Wišo authored and tgrk committed Jun 30, 2022
1 parent a215645 commit 6da230e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/excoveralls/poster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ defmodule ExCoveralls.Poster do
{:ok, status_code, _, _} when status_code in 200..299 ->
{:ok, "Successfully uploaded the report to '#{endpoint}'."}

{:ok, 500 = _status_code, _, _client} ->
{:ok, "API endpoint `#{endpoint}` is not available and return internal server error! Ignoring upload"}
{:ok, status_code, _, client} ->
{:ok, body} = :hackney.body(client)

Expand Down
11 changes: 11 additions & 0 deletions test/poster_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ defmodule PosterTest do
assert ExCoveralls.Poster.execute("json") == :ok
end) =~ ~r/timeout/
end
test_with_mock "post json fails due internal server error", :hackney, [request: fn(_, _, _, _, _) -> {:ok, 500, "", ""} end] do
assert capture_io(fn ->
assert ExCoveralls.Poster.execute("json") == :ok
end) =~ ~r/internal server error/
end

test_with_mock "post json fails due to maintenance", :hackney, [request: fn(_, _, _, _, _) -> {:ok, 405, "", ""} end] do
assert capture_io(fn ->
assert ExCoveralls.Poster.execute("json") == :ok
end) =~ ~r/maintenance/
end
end

0 comments on commit 6da230e

Please sign in to comment.