Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn when unknown objects are processed #514

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lib/stripe/converter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ defmodule Stripe.Converter do
@spec convert_value(any) :: any
defp convert_value(%{"object" => object_name} = value) when is_binary(object_name) do
case Enum.member?(@supported_objects, object_name) do
true -> convert_stripe_object(value)
false -> convert_map(value)
true ->
convert_stripe_object(value)

false ->
warn_unknown_object(value)
convert_map(value)
end
end

Expand Down Expand Up @@ -109,6 +113,16 @@ defmodule Stripe.Converter do
@spec convert_list(list) :: list
defp convert_list(list), do: list |> Enum.map(&convert_value/1)

if Mix.env() == "prod" do
defp warn_unknown_object(_), do: :ok
else
defp warn_unknown_object(%{"object" => object_name} = value) do
require Logger

Logger.warn("Unknown object received: #{object_name}")
end
end

if Mix.env() == "prod" do
defp check_for_extra_keys(_, _), do: :ok
else
Expand Down Expand Up @@ -140,7 +154,7 @@ defmodule Stripe.Converter do

details = "#{module_name}: #{inspect(extra_keys)}"
message = "Extra keys were received but ignored when converting #{details}"
Logger.debug(message)
Logger.warn(message)
end

:ok
Expand Down