diff --git a/lib/excoveralls/poster.ex b/lib/excoveralls/poster.ex index fba50f3..fca0a6e 100644 --- a/lib/excoveralls/poster.ex +++ b/lib/excoveralls/poster.ex @@ -43,6 +43,10 @@ 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, 405 = _status_code, _, _client} -> + {:ok, "API endpoint `#{endpoint}` is not available due to maintenance! Ignoring upload"} {:ok, status_code, _, client} -> {:ok, body} = :hackney.body(client) diff --git a/test/poster_test.exs b/test/poster_test.exs index a5e0791..ad3952e 100644 --- a/test/poster_test.exs +++ b/test/poster_test.exs @@ -21,4 +21,16 @@ 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