diff --git a/lib/rollbax.ex b/lib/rollbax.ex index 012c305..1ffb059 100644 --- a/lib/rollbax.ex +++ b/lib/rollbax.ex @@ -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 diff --git a/lib/rollbax/exception.ex b/lib/rollbax/exception.ex index 5b65208..6720e27 100644 --- a/lib/rollbax/exception.ex +++ b/lib/rollbax/exception.ex @@ -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 @@ -10,6 +11,7 @@ defmodule Rollbax.Exception do defstruct [ :class, :message, + :description, :stacktrace, custom: %{}, occurrence_data: %{} diff --git a/lib/rollbax/item.ex b/lib/rollbax/item.ex index 1ad737b..21fa5e7 100644 --- a/lib/rollbax/item.ex +++ b/lib/rollbax/item.ex @@ -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 @@ -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