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

Add ability to specify description in Rollbax.Exception #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion lib/rollbax.ex
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,13 @@ defmodule Rollbax do
%{
class: class,
message: message,
description: description,
stacktrace: stacktrace,
custom: custom,
occurrence_data: occurrence_data
} = exception

body = Rollbax.Item.exception_body(class, message, stacktrace)
body = Rollbax.Item.exception_body(class, message, description, stacktrace)
Rollbax.Client.emit(:error, System.system_time(:second), body, custom, occurrence_data)
end
end
2 changes: 2 additions & 0 deletions lib/rollbax/exception.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Rollbax.Exception do
@type t :: %__MODULE__{
class: String.t(),
message: String.t(),
description: String.t(),
stacktrace: Exception.stacktrace(),
custom: map,
occurrence_data: map
Expand All @@ -10,6 +11,7 @@ defmodule Rollbax.Exception do
defstruct [
:class,
:message,
:description,
:stacktrace,
custom: %{},
occurrence_data: %{}
Expand Down
10 changes: 7 additions & 3 deletions lib/rollbax/item.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ defmodule Rollbax.Item do
`class` and `message` are strings that will be used as the class and message
of the reported exception. `stacktrace` is the stacktrace of the error.
"""
@spec exception_body(String.t(), String.t(), [any]) :: map
def exception_body(class, message, stacktrace)
@spec exception_body(String.t(), String.t(), String.t() | nil, [any]) :: map
def exception_body(class, message, description \\ nil, stacktrace)
when is_binary(class) and is_binary(message) and is_list(stacktrace) do
%{
"trace" => %{
"frames" => stacktrace_to_frames(stacktrace),
"exception" => %{
"class" => class,
"message" => message
"message" => message,
}
|> put_if_present("description", description)
}
}
end
Expand Down Expand Up @@ -166,4 +167,7 @@ defmodule Rollbax.Item do
"version" => unquote(Mix.Project.config()[:version])
}
end

defp put_if_present(map, _field, nil), do: map
defp put_if_present(map, field, value), do: Map.put(map, field, value)
end