@@ -7,17 +7,23 @@ defmodule Sentry.PlugCaptureTest do
77 defmodule PhoenixController do
88 use Phoenix.Controller
99 def error ( _conn , _params ) , do: raise ( "PhoenixError" )
10+
11+ def assigns ( conn , _params ) do
12+ _test = conn . assigns2 . test
13+ end
1014 end
1115
1216 defmodule PhoenixRouter do
1317 use Phoenix.Router
1418
1519 get "/error_route" , PhoenixController , :error
20+ get "/assigns_route" , PhoenixController , :assigns
1621 end
1722
1823 defmodule PhoenixEndpoint do
1924 use Sentry.PlugCapture
2025 use Phoenix.Endpoint , otp_app: :sentry
26+ use Plug.Debugger , otp_app: :sentry
2127
2228 plug Plug.Parsers ,
2329 parsers: [ :urlencoded , :multipart , :json ] ,
@@ -215,4 +221,32 @@ defmodule Sentry.PlugCaptureTest do
215221 assert body =~ event_id
216222 assert body =~ ~s{ "title":"Testing"}
217223 end
224+
225+ test "handles Erlang error in Plug.Conn.WrapperError" do
226+ bypass = Bypass . open ( )
227+
228+ Bypass . expect ( bypass , fn conn ->
229+ { :ok , body , conn } = Plug.Conn . read_body ( conn )
230+ json = Jason . decode! ( body )
231+ assert json [ "culprit" ] == "Sentry.PlugCaptureTest.PhoenixController.assigns/2"
232+ Plug.Conn . resp ( conn , 200 , ~s< {"id": "340"}> )
233+ end )
234+
235+ modify_env ( :sentry ,
236+ dsn: "http://public:secret@localhost:#{ bypass . port } /1" ,
237+ "#{ __MODULE__ . PhoenixEndpoint } ": [
238+ render_errors: [ view: Sentry.ErrorView , accepts: ~w( html) ]
239+ ]
240+ )
241+
242+ { :ok , _ } = PhoenixEndpoint . start_link ( )
243+
244+ capture_log ( fn ->
245+ assert_raise KeyError , fn ->
246+ conn ( :get , "/assigns_route" )
247+ |> Plug.Conn . put_req_header ( "throw" , "throw" )
248+ |> PhoenixEndpoint . call ( [ ] )
249+ end
250+ end )
251+ end
218252end
0 commit comments