Skip to content

Commit

Permalink
fix: pattern match response codes via ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceEEC committed Nov 2, 2018
1 parent 2b0f25e commit f2f0090
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/rest/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ defmodule Crux.Rest.Base do
defp handle_response({:error, _} = error, _method), do: error
defp handle_response({:ok, %HTTPoison.Response{status_code: 204}}, _method), do: :ok

defp handle_response({:ok, %HTTPoison.Response{status_code: 200, body: body}}, _method) do
defp handle_response({:ok, %HTTPoison.Response{status_code: code, body: body}}, _method)
when code in 200..299 do
with {:error, _} <- Poison.decode(body) do
{:error, {:decoding, body}}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rest/handler/handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ defmodule Crux.Rest.Handler do
%{route: route} = state,
_
)
when code >= 500 and code < 600 do
when code in 500..599 do
Logger.warn(
"[Crux][Rest][Handler][#{route}] Received a #{code}" <>
" [#{Map.get(state, :retries, 0)}/#{@max_retries_on_5xx}]"
Expand Down

0 comments on commit f2f0090

Please sign in to comment.