@@ -217,7 +217,7 @@ where
217
217
} ;
218
218
219
219
// Response errors
220
- if inner. capture_server_errors {
220
+ if inner. capture_server_errors && res . response ( ) . status ( ) . is_server_error ( ) {
221
221
if let Some ( e) = res. response ( ) . error ( ) {
222
222
let event_id = hub. capture_error ( e) ;
223
223
@@ -329,8 +329,6 @@ mod tests {
329
329
async fn test_explicit_events ( ) {
330
330
let events = sentry:: test:: with_captured_events ( || {
331
331
block_on ( async {
332
- let test_hub = Hub :: current ( ) ;
333
-
334
332
let service = || {
335
333
// Current Hub should have no events
336
334
_assert_hub_no_events ( ) ;
@@ -345,7 +343,7 @@ mod tests {
345
343
346
344
let mut app = init_service (
347
345
App :: new ( )
348
- . wrap ( Sentry :: builder ( ) . with_hub ( test_hub ) . finish ( ) )
346
+ . wrap ( Sentry :: builder ( ) . with_hub ( Hub :: current ( ) ) . finish ( ) )
349
347
. service ( web:: resource ( "/test" ) . to ( service) ) ,
350
348
)
351
349
. await ;
@@ -374,8 +372,6 @@ mod tests {
374
372
async fn test_response_errors ( ) {
375
373
let events = sentry:: test:: with_captured_events ( || {
376
374
block_on ( async {
377
- let test_hub = Hub :: current ( ) ;
378
-
379
375
#[ get( "/test" ) ]
380
376
async fn failing ( _req : HttpRequest ) -> Result < String , Error > {
381
377
// Current hub should have no events
@@ -386,7 +382,7 @@ mod tests {
386
382
387
383
let mut app = init_service (
388
384
App :: new ( )
389
- . wrap ( Sentry :: builder ( ) . with_hub ( test_hub ) . finish ( ) )
385
+ . wrap ( Sentry :: builder ( ) . with_hub ( Hub :: current ( ) ) . finish ( ) )
390
386
. service ( failing) ,
391
387
)
392
388
. await ;
@@ -411,4 +407,27 @@ mod tests {
411
407
assert_eq ! ( request. method, Some ( "GET" . into( ) ) ) ;
412
408
}
413
409
}
410
+
411
+ /// Ensures client errors (4xx) are not captured.
412
+ #[ actix_rt:: test]
413
+ async fn test_client_errors_discarded ( ) {
414
+ let events = sentry:: test:: with_captured_events ( || {
415
+ block_on ( async {
416
+ let service = || HttpResponse :: NotFound ( ) ;
417
+
418
+ let mut app = init_service (
419
+ App :: new ( )
420
+ . wrap ( Sentry :: builder ( ) . with_hub ( Hub :: current ( ) ) . finish ( ) )
421
+ . service ( web:: resource ( "/test" ) . to ( service) ) ,
422
+ )
423
+ . await ;
424
+
425
+ let req = TestRequest :: get ( ) . uri ( "/test" ) . to_request ( ) ;
426
+ let res = call_service ( & mut app, req) . await ;
427
+ assert ! ( res. status( ) . is_client_error( ) ) ;
428
+ } )
429
+ } ) ;
430
+
431
+ assert ! ( events. is_empty( ) ) ;
432
+ }
414
433
}
0 commit comments