Current section
Files
Jump to
Current section
Files
lib/error_handler.ex
defmodule CoreUtils.ErrorHandler do
require Logger
def handle(kind, reason, stacktrace) do
kind |> inspect() |> Logger.warn(label: "kind")
reason |> inspect() |> Logger.warn(label: "reason")
stacktrace |> inspect() |> Logger.warn(label: "stacktrace")
handle(Exception.normalize(kind, reason, stacktrace), stacktrace)
end
def handle(exception, stacktrace) do
Logger.warn("Error in handler sentry #{inspect(exception)}")
spawn(__MODULE__, :sentry_report, [exception, stacktrace])
{:reply,
%{
status: :error,
code: 0,
message: inspect(exception)
}}
end
def sentry_report(exception, stacktrace) do
try do
exception
|> Sentry.capture_exception(
stacktrace: stacktrace,
event_source: "microservice",
level: :warn
)
rescue
exception ->
Logger.warn(exception, label: "Rescue in sentry")
catch
_, reason ->
Logger.warn(reason, label: "Catch in sentry")
end
end
end