@@ -7,6 +7,8 @@ defmodule Sentry.PlugCaptureTest do
77 defmodule PhoenixController do
88 use Phoenix.Controller
99 def error ( _conn , _params ) , do: raise ( "PhoenixError" )
10+ def exit ( _conn , _params ) , do: exit ( :test )
11+ def throw ( _conn , _params ) , do: throw ( :test )
1012
1113 def assigns ( conn , _params ) do
1214 _test = conn . assigns2 . test
@@ -17,6 +19,8 @@ defmodule Sentry.PlugCaptureTest do
1719 use Phoenix.Router
1820
1921 get "/error_route" , PhoenixController , :error
22+ get "/exit_route" , PhoenixController , :exit
23+ get "/throw_route" , PhoenixController , :throw
2024 get "/assigns_route" , PhoenixController , :assigns
2125 end
2226
@@ -56,6 +60,40 @@ defmodule Sentry.PlugCaptureTest do
5660 end )
5761 end
5862
63+ test "sends throws to Sentry" do
64+ bypass = Bypass . open ( )
65+
66+ Bypass . expect ( bypass , fn conn ->
67+ { :ok , body , conn } = Plug.Conn . read_body ( conn )
68+ _json = Jason . decode! ( body )
69+ Plug.Conn . resp ( conn , 200 , ~s< {"id": "340"}> )
70+ end )
71+
72+ modify_env ( :sentry , dsn: "http://public:secret@localhost:#{ bypass . port } /1" )
73+
74+ catch_throw (
75+ conn ( :get , "/throw_route" )
76+ |> Sentry.ExamplePlugApplication . call ( [ ] )
77+ )
78+ end
79+
80+ test "sends exits to Sentry" do
81+ bypass = Bypass . open ( )
82+
83+ Bypass . expect ( bypass , fn conn ->
84+ { :ok , body , conn } = Plug.Conn . read_body ( conn )
85+ _json = Jason . decode! ( body )
86+ Plug.Conn . resp ( conn , 200 , ~s< {"id": "340"}> )
87+ end )
88+
89+ modify_env ( :sentry , dsn: "http://public:secret@localhost:#{ bypass . port } /1" )
90+
91+ catch_exit (
92+ conn ( :get , "/exit_route" )
93+ |> Sentry.ExamplePlugApplication . call ( [ ] )
94+ )
95+ end
96+
5997 test "works with Sentry.PlugContext" do
6098 bypass = Bypass . open ( )
6199
@@ -131,6 +169,56 @@ defmodule Sentry.PlugCaptureTest do
131169 end )
132170 end
133171
172+ test "reports exits occurring in Phoenix Endpoint" do
173+ bypass = Bypass . open ( )
174+
175+ Bypass . expect ( bypass , fn conn ->
176+ { :ok , body , conn } = Plug.Conn . read_body ( conn )
177+ json = Jason . decode! ( body )
178+ assert json [ "culprit" ] == "Sentry.PlugCaptureTest.PhoenixController.exit/2"
179+ assert json [ "message" ] == "Uncaught exit - :test"
180+ Plug.Conn . resp ( conn , 200 , ~s< {"id": "340"}> )
181+ end )
182+
183+ modify_env ( :sentry ,
184+ dsn: "http://public:secret@localhost:#{ bypass . port } /1" ,
185+ "#{ __MODULE__ . PhoenixEndpoint } ": [
186+ render_errors: [ view: Sentry.ErrorView , accepts: ~w( html) ]
187+ ]
188+ )
189+
190+ { :ok , _ } = PhoenixEndpoint . start_link ( )
191+
192+ capture_log ( fn ->
193+ catch_exit ( conn ( :get , "/exit_route" ) |> PhoenixEndpoint . call ( [ ] ) )
194+ end )
195+ end
196+
197+ test "reports throws occurring in Phoenix Endpoint" do
198+ bypass = Bypass . open ( )
199+
200+ Bypass . expect ( bypass , fn conn ->
201+ { :ok , body , conn } = Plug.Conn . read_body ( conn )
202+ json = Jason . decode! ( body )
203+ assert json [ "culprit" ] == "Sentry.PlugCaptureTest.PhoenixController.throw/2"
204+ assert json [ "message" ] == "Uncaught throw - :test"
205+ Plug.Conn . resp ( conn , 200 , ~s< {"id": "340"}> )
206+ end )
207+
208+ modify_env ( :sentry ,
209+ dsn: "http://public:secret@localhost:#{ bypass . port } /1" ,
210+ "#{ __MODULE__ . PhoenixEndpoint } ": [
211+ render_errors: [ view: Sentry.ErrorView , accepts: ~w( html) ]
212+ ]
213+ )
214+
215+ { :ok , _ } = PhoenixEndpoint . start_link ( )
216+
217+ capture_log ( fn ->
218+ catch_throw ( conn ( :get , "/throw_route" ) |> PhoenixEndpoint . call ( [ ] ) )
219+ end )
220+ end
221+
134222 test "can render feedback form in Phoenix ErrorView" do
135223 bypass = Bypass . open ( )
136224
0 commit comments