diff --git a/dev.exs b/dev.exs index 437f027..b02d8e6 100644 --- a/dev.exs +++ b/dev.exs @@ -59,6 +59,7 @@ defmodule ErrorTrackerDevWeb.PageController do
Generate Router 404
Raise NoRouteError from a controller
Generate Exception
+
Generate Exit
""") end @@ -70,6 +71,10 @@ defmodule ErrorTrackerDevWeb.PageController do raise "This is a controller exception" end + def call(_conn, :exit) do + exit(:timeout) + end + defp content(conn, content) do conn |> put_resp_header("content-type", "text/html") @@ -100,6 +105,7 @@ defmodule ErrorTrackerDevWeb.Router do get "/", ErrorTrackerDevWeb.PageController, :index get "/noroute", ErrorTrackerDevWeb.PageController, :noroute get "/exception", ErrorTrackerDevWeb.PageController, :exception + get "/exit", ErrorTrackerDevWeb.PageController, :exit end end diff --git a/lib/error_tracker/integrations/phoenix.ex b/lib/error_tracker/integrations/phoenix.ex index 1bb577d..dd32520 100644 --- a/lib/error_tracker/integrations/phoenix.ex +++ b/lib/error_tracker/integrations/phoenix.ex @@ -27,15 +27,15 @@ defmodule ErrorTracker.Integrations.Phoenix do end def handle_event([:phoenix, :router_dispatch, :exception], _measurements, metadata, :no_config) do - {reason, stack} = + {reason, kind, stack} = case metadata do - %{reason: %Plug.Conn.WrapperError{reason: reason, stack: stack}} -> - {reason, stack} + %{reason: %Plug.Conn.WrapperError{reason: reason, kind: kind, stack: stack}} -> + {reason, kind, stack} - %{reason: reason, stacktrace: stack} -> - {reason, stack} + %{kind: kind, reason: reason, stacktrace: stack} -> + {reason, kind, stack} end - PlugIntegration.report_error(metadata.conn, reason, stack) + PlugIntegration.report_error(metadata.conn, {reason, kind}, stack) end end diff --git a/lib/error_tracker/integrations/plug.ex b/lib/error_tracker/integrations/plug.ex index 6c56bbd..76362a4 100644 --- a/lib/error_tracker/integrations/plug.ex +++ b/lib/error_tracker/integrations/plug.ex @@ -62,7 +62,7 @@ defmodule ErrorTracker.Integrations.Plug do catch kind, reason -> stack = __STACKTRACE__ - unquote(__MODULE__).report_error(conn, reason, stack) + unquote(__MODULE__).report_error(conn, {kind, reason}, stack) :erlang.raise(kind, reason, stack) end diff --git a/lib/error_tracker/schemas/error.ex b/lib/error_tracker/schemas/error.ex index 6bcfbdf..828ee53 100644 --- a/lib/error_tracker/schemas/error.ex +++ b/lib/error_tracker/schemas/error.ex @@ -24,9 +24,21 @@ defmodule ErrorTracker.Error do def new(exception, stacktrace = %ErrorTracker.Stacktrace{}) do source = ErrorTracker.Stacktrace.source(stacktrace) + {kind, reason} = + case exception do + %struct{} = ex when is_exception(ex) -> + {to_string(struct), Exception.message(ex)} + + {_kind, %struct{} = ex} when is_exception(ex) -> + {to_string(struct), Exception.message(ex)} + + {kind, ex} -> + {to_string(kind), to_string(ex)} + end + params = [ - kind: "error", - reason: Exception.message(exception), + kind: to_string(kind), + reason: reason, source_line: "#{source.file}:#{source.line}", source_function: "#{source.module}.#{source.function}/#{source.arity}" ]