Navigation Menu

Skip to content

Commit

Permalink
trying
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellhenke committed Aug 24, 2016
1 parent b49321f commit ddb721b
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions lib/sentry/plug.ex
@@ -1,33 +1,16 @@
defmodule Sentry.Plug do
defmacro __using__(_env) do
quote do
def call(conn, opts) do
try do
super(conn, opts)
catch
kind, reason ->
Sentry.Plug.__catch__(conn, kind, reason)
end
use Plug.ErrorHandler

This comment has been minimized.

Copy link
@jeregrine

jeregrine Aug 24, 2016

Contributor

I wouldn't add this. If they are using Phoenix it's handled, if they are not we can document it.


defp handle_errors(conn, %{kind: kind, reason: reason, stack: stack}) do
request = Sentry.Plug.build_request_interface_data(conn)
exception = Exception.normalize(kind, reason, stack)
Sentry.capture_exception(exception, [stacktrace: stack, request: request])
end
end
end

def __catch__(_conn, :error, %Plug.Conn.WrapperError{} = wrapper) do
%{conn: conn, kind: kind, reason: reason, stack: stack} = wrapper
__catch__(conn, kind, reason, stack)
end

def __catch__(conn, kind, reason) do
__catch__(conn, kind, reason, System.stacktrace())
end

def __catch__(conn, kind, reason, stack) do
request = Sentry.Plug.build_request_interface_data(conn)
exception = Exception.normalize(kind, reason, stack)
Sentry.capture_exception(exception, [stacktrace: stack, request: request])
:erlang.raise(kind, reason, stack)
end

def build_request_interface_data(%Plug.Conn{} = conn) do
conn = conn
|> Plug.Conn.fetch_cookies
Expand Down

0 comments on commit ddb721b

Please sign in to comment.