@@ -217,7 +217,7 @@ where
217217 } ;
218218
219219 // Response errors
220- if inner. capture_server_errors {
220+ if inner. capture_server_errors && res . response ( ) . status ( ) . is_server_error ( ) {
221221 if let Some ( e) = res. response ( ) . error ( ) {
222222 let event_id = hub. capture_error ( e) ;
223223
@@ -329,8 +329,6 @@ mod tests {
329329 async fn test_explicit_events ( ) {
330330 let events = sentry:: test:: with_captured_events ( || {
331331 block_on ( async {
332- let test_hub = Hub :: current ( ) ;
333-
334332 let service = || {
335333 // Current Hub should have no events
336334 _assert_hub_no_events ( ) ;
@@ -345,7 +343,7 @@ mod tests {
345343
346344 let mut app = init_service (
347345 App :: new ( )
348- . wrap ( Sentry :: builder ( ) . with_hub ( test_hub ) . finish ( ) )
346+ . wrap ( Sentry :: builder ( ) . with_hub ( Hub :: current ( ) ) . finish ( ) )
349347 . service ( web:: resource ( "/test" ) . to ( service) ) ,
350348 )
351349 . await ;
@@ -374,8 +372,6 @@ mod tests {
374372 async fn test_response_errors ( ) {
375373 let events = sentry:: test:: with_captured_events ( || {
376374 block_on ( async {
377- let test_hub = Hub :: current ( ) ;
378-
379375 #[ get( "/test" ) ]
380376 async fn failing ( _req : HttpRequest ) -> Result < String , Error > {
381377 // Current hub should have no events
@@ -386,7 +382,7 @@ mod tests {
386382
387383 let mut app = init_service (
388384 App :: new ( )
389- . wrap ( Sentry :: builder ( ) . with_hub ( test_hub ) . finish ( ) )
385+ . wrap ( Sentry :: builder ( ) . with_hub ( Hub :: current ( ) ) . finish ( ) )
390386 . service ( failing) ,
391387 )
392388 . await ;
@@ -411,4 +407,27 @@ mod tests {
411407 assert_eq ! ( request. method, Some ( "GET" . into( ) ) ) ;
412408 }
413409 }
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+ }
414433}
0 commit comments