Skip to content

Commit

Permalink
fix: handle non-JSON responses properly
Browse files Browse the repository at this point in the history
Thank you, Cloudflare
  • Loading branch information
SpaceEEC committed Sep 14, 2019
1 parent b644f9f commit 6c23b5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/rest/api_error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ defmodule Crux.Rest.ApiError do
}
end

# Thank you, Cloudflare
def exception(%{method: method, path: path}, %{status_code: status_code, body: message})
when is_binary(message) do
%__MODULE__{
status_code: status_code,
code: nil,
message: message,
path: path,
method: method
}
end

defp map_inner(error, key \\ nil)
defp map_inner(nil, _key), do: nil

Expand Down
2 changes: 1 addition & 1 deletion lib/rest/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ defmodule Crux.Rest.HTTP do
%{res | body: body}

_ ->
body
res
end
end

Expand Down

0 comments on commit 6c23b5f

Please sign in to comment.