@@ -71,15 +71,15 @@ def test_transaction_style(
71
71
assert event ["transaction" ] == expected_transaction
72
72
73
73
74
- def test_errors (sentry_init , capture_exceptions , capture_events ):
74
+ def test_unhandled_errors (sentry_init , capture_exceptions , capture_events ):
75
75
sentry_init (integrations = [FalconIntegration ()], debug = True )
76
76
77
- class ZeroDivisionErrorResource :
77
+ class Resource :
78
78
def on_get (self , req , resp ):
79
79
1 / 0
80
80
81
81
app = falcon .API ()
82
- app .add_route ("/" , ZeroDivisionErrorResource ())
82
+ app .add_route ("/" , Resource ())
83
83
84
84
exceptions = capture_exceptions ()
85
85
events = capture_events ()
@@ -96,6 +96,75 @@ def on_get(self, req, resp):
96
96
97
97
(event ,) = events
98
98
assert event ["exception" ]["values" ][0 ]["mechanism" ]["type" ] == "falcon"
99
+ assert " by zero" in event ["exception" ]["values" ][0 ]["value" ]
100
+
101
+
102
+ def test_raised_5xx_errors (sentry_init , capture_exceptions , capture_events ):
103
+ sentry_init (integrations = [FalconIntegration ()], debug = True )
104
+
105
+ class Resource :
106
+ def on_get (self , req , resp ):
107
+ raise falcon .HTTPError (falcon .HTTP_502 )
108
+
109
+ app = falcon .API ()
110
+ app .add_route ("/" , Resource ())
111
+
112
+ exceptions = capture_exceptions ()
113
+ events = capture_events ()
114
+
115
+ client = falcon .testing .TestClient (app )
116
+ client .simulate_get ("/" )
117
+
118
+ (exc ,) = exceptions
119
+ assert isinstance (exc , falcon .HTTPError )
120
+
121
+ (event ,) = events
122
+ assert event ["exception" ]["values" ][0 ]["mechanism" ]["type" ] == "falcon"
123
+ assert event ["exception" ]["values" ][0 ]["type" ] == "HTTPError"
124
+
125
+
126
+ def test_raised_4xx_errors (sentry_init , capture_exceptions , capture_events ):
127
+ sentry_init (integrations = [FalconIntegration ()], debug = True )
128
+
129
+ class Resource :
130
+ def on_get (self , req , resp ):
131
+ raise falcon .HTTPError (falcon .HTTP_400 )
132
+
133
+ app = falcon .API ()
134
+ app .add_route ("/" , Resource ())
135
+
136
+ exceptions = capture_exceptions ()
137
+ events = capture_events ()
138
+
139
+ client = falcon .testing .TestClient (app )
140
+ client .simulate_get ("/" )
141
+
142
+ assert len (exceptions ) == 0
143
+ assert len (events ) == 0
144
+
145
+
146
+ def test_http_status (sentry_init , capture_exceptions , capture_events ):
147
+ """
148
+ This just demonstrates, that if Falcon raises a HTTPStatus with code 500
149
+ (instead of a HTTPError with code 500) Sentry will not capture it.
150
+ """
151
+ sentry_init (integrations = [FalconIntegration ()], debug = True )
152
+
153
+ class Resource :
154
+ def on_get (self , req , resp ):
155
+ raise falcon .http_status .HTTPStatus (falcon .HTTP_508 )
156
+
157
+ app = falcon .API ()
158
+ app .add_route ("/" , Resource ())
159
+
160
+ exceptions = capture_exceptions ()
161
+ events = capture_events ()
162
+
163
+ client = falcon .testing .TestClient (app )
164
+ client .simulate_get ("/" )
165
+
166
+ assert len (exceptions ) == 0
167
+ assert len (events ) == 0
99
168
100
169
101
170
def test_falcon_large_json_request (sentry_init , capture_events ):
0 commit comments