Skip to content

Commit

Permalink
Handle structs explicitly when adding error type
Browse files Browse the repository at this point in the history
We want to avoid assuming that all errors reasons are either nil
or structs. This rearranges the clauses and uses pattern matching
to handle the struct case, allowing us to handle anything else
like we handled the nil case before.
  • Loading branch information
cararemixed authored and GregMefford committed Sep 25, 2021
1 parent 3ad01ea commit 4a85d52
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/spandex_datadog/api_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ defmodule SpandexDatadog.ApiServer do
end

@spec add_error_type(map, Exception.t() | nil) :: map
defp add_error_type(meta, nil), do: meta
defp add_error_type(meta, exception), do: Map.put(meta, "error.type", exception.__struct__)
defp add_error_type(meta, %struct{}), do: Map.put(meta, "error.type", struct)
defp add_error_type(meta, _), do: meta

@spec add_error_message(map, Exception.t() | nil) :: map
defp add_error_message(meta, nil), do: meta
Expand Down

0 comments on commit 4a85d52

Please sign in to comment.