Skip to content

Commit

Permalink
Change log level
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsmith committed Nov 22, 2017
1 parent dfd9b71 commit 72a0d9e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions config/dev.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use Mix.Config

config :logger, level: :debug
13 changes: 9 additions & 4 deletions lib/stripe/converter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,16 @@ defmodule Stripe.Converter do
|> Enum.to_list()

unless Enum.empty?(extra_keys) do
object_and_keys = "#{map["object"]}: #{inspect(extra_keys)}"
object = Map.get(map, "object")

Logger.error(
"Extra keys were received but ignored when converting Stripe object #{object_and_keys}"
)
module_name =
object
|> Stripe.Util.object_name_to_module()
|> Stripe.Util.module_to_string()

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

:ok
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ defmodule Stripe.Error do
defp message_from_type(:validation_error),
do: "A client-side library failed to validate a field."

defp maybe_put(map, key, nil), do: map
defp maybe_put(map, _key, nil), do: map
defp maybe_put(map, key, value), do: map |> Map.put(key, value)

defp maybe_to_atom(nil), do: nil
Expand Down
5 changes: 5 additions & 0 deletions lib/stripe/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ defmodule Stripe.Util do
Module.concat("Stripe", module_name)
end

@spec module_to_string(module) :: String.t()
def module_to_string(module) do
module |> Atom.to_string() |> String.trim_leading("Elixir.")
end

def normalize_id(%{id: id}) when id !== nil, do: id
def normalize_id(id) when is_binary(id), do: id

Expand Down
1 change: 1 addition & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Logger.configure(level: :info)
Process.sleep(250)
Application.put_env(:stripity_stripe, :api_base_url, "http://localhost:12123/v1/")
Application.put_env(:stripity_stripe, :api_key, "sk_test_123")
Application.put_env(:stripity_stripe, :log_level, :debug)

defmodule Helper do
@fixture_path "./test/fixtures/"
Expand Down

0 comments on commit 72a0d9e

Please sign in to comment.