@@ -525,15 +525,15 @@ private void Snapshot(object isCalledFromTimer)
525525 LastSerializationInfo = info ;
526526 AfterSerialization ? . Invoke ( info ) ;
527527 }
528- catch ( Exception e )
528+ catch ( Exception ex )
529529 {
530- if ( HasExceptionHandler )
530+ if ( ShouldThrowException ( ex ) )
531531 {
532- OnBackgroundException ( e ) ;
533- return ;
532+ if ( HasExceptionHandler )
533+ OnBackgroundException ( ex ) ;
534+ else
535+ throw ;
534536 }
535-
536- throw ;
537537 }
538538 }
539539
@@ -573,11 +573,11 @@ private void Flush(object isCalledFromTimer)
573573
574574 } while ( any ) ;
575575 }
576- catch ( BosunPostException ex )
576+ catch ( Exception ex )
577577 {
578578 // there was a problem flushing - back off for the next five seconds (Bosun may simply be restarting)
579579 _skipFlushes = 4 ;
580- if ( ThrowOnPostFail )
580+ if ( ShouldThrowException ( ex ) )
581581 {
582582 if ( HasExceptionHandler )
583583 OnBackgroundException ( ex ) ;
@@ -784,12 +784,15 @@ private void PostMetaData(object _)
784784 }
785785 } ) ;
786786 }
787- catch ( BosunPostException ex )
787+ catch ( Exception ex )
788788 {
789- if ( HasExceptionHandler )
790- OnBackgroundException ( ex ) ;
791- else
792- throw ;
789+ if ( ShouldThrowException ( ex ) )
790+ {
791+ if ( HasExceptionHandler )
792+ OnBackgroundException ( ex ) ;
793+ else
794+ throw ;
795+ }
793796 }
794797 }
795798
@@ -826,14 +829,32 @@ private string GatherMetaData()
826829
827830 private void OnPayloadDropped ( BosunQueueFullException ex )
828831 {
829- if ( ThrowOnQueueFull )
832+ if ( ShouldThrowException ( ex ) )
830833 {
831834 if ( HasExceptionHandler )
832835 OnBackgroundException ( ex ) ;
833836 else
834837 throw ex ;
835838 }
836839 }
840+
841+ private bool ShouldThrowException ( Exception ex )
842+ {
843+ var post = ex as BosunPostException ;
844+ if ( post != null )
845+ {
846+ if ( ThrowOnPostFail )
847+ return true ;
848+
849+ var status = ( int ) post . StatusCode ;
850+ return status < 500 || status >= 600 ; // always want to send the exception when it's a non-500
851+ }
852+
853+ if ( ex is BosunQueueFullException )
854+ return ThrowOnQueueFull ;
855+
856+ return true ;
857+ }
837858 }
838859
839860 public class AfterSerializationInfo
0 commit comments