@@ -404,10 +404,11 @@ static <T> CheckedFunction0<T> decorateCheckedSupplier(CircuitBreaker circuitBre
404
404
long durationInNanos = System .nanoTime () - start ;
405
405
circuitBreaker .onSuccess (durationInNanos );
406
406
return returnValue ;
407
- } catch (Throwable throwable ) {
407
+ } catch (Exception exception ) {
408
+ // Do not handle java.lang.Error
408
409
long durationInNanos = System .nanoTime () - start ;
409
- circuitBreaker .onError (durationInNanos , throwable );
410
- throw throwable ;
410
+ circuitBreaker .onError (durationInNanos , exception );
411
+ throw exception ;
411
412
}
412
413
};
413
414
}
@@ -439,12 +440,15 @@ static <T> Supplier<CompletionStage<T>> decorateCompletionStage(
439
440
try {
440
441
supplier .get ().whenComplete ((result , throwable ) -> {
441
442
long durationInNanos = System .nanoTime () - start ;
442
- if (throwable != null ) {
443
- circuitBreaker .onError (durationInNanos , throwable );
444
- promise .completeExceptionally (throwable );
445
- } else {
443
+ if (result != null ) {
446
444
circuitBreaker .onSuccess (durationInNanos );
447
445
promise .complete (result );
446
+ } else if (throwable instanceof Exception ) {
447
+ circuitBreaker .onError (durationInNanos , throwable );
448
+ promise .completeExceptionally (throwable );
449
+ } else {
450
+ // Do not handle java.lang.Error
451
+ promise .completeExceptionally (throwable );
448
452
}
449
453
});
450
454
} catch (Throwable throwable ) {
@@ -474,10 +478,11 @@ static CheckedRunnable decorateCheckedRunnable(CircuitBreaker circuitBreaker, Ch
474
478
runnable .run ();
475
479
long durationInNanos = System .nanoTime () - start ;
476
480
circuitBreaker .onSuccess (durationInNanos );
477
- } catch (Throwable throwable ){
481
+ } catch (Exception exception ){
482
+ // Do not handle java.lang.Error
478
483
long durationInNanos = System .nanoTime () - start ;
479
- circuitBreaker .onError (durationInNanos , throwable );
480
- throw throwable ;
484
+ circuitBreaker .onError (durationInNanos , exception );
485
+ throw exception ;
481
486
}
482
487
};
483
488
}
@@ -500,10 +505,11 @@ static <T> Callable<T> decorateCallable(CircuitBreaker circuitBreaker, Callable<
500
505
long durationInNanos = System .nanoTime () - start ;
501
506
circuitBreaker .onSuccess (durationInNanos );
502
507
return returnValue ;
503
- } catch (Throwable throwable ) {
508
+ } catch (Exception exception ) {
509
+ // Do not handle java.lang.Error
504
510
long durationInNanos = System .nanoTime () - start ;
505
- circuitBreaker .onError (durationInNanos , throwable );
506
- throw throwable ;
511
+ circuitBreaker .onError (durationInNanos , exception );
512
+ throw exception ;
507
513
}
508
514
};
509
515
}
@@ -526,10 +532,11 @@ static <T> Supplier<T> decorateSupplier(CircuitBreaker circuitBreaker, Supplier<
526
532
long durationInNanos = System .nanoTime () - start ;
527
533
circuitBreaker .onSuccess (durationInNanos );
528
534
return returnValue ;
529
- } catch (Throwable throwable ) {
535
+ } catch (Exception exception ) {
536
+ // Do not handle java.lang.Error
530
537
long durationInNanos = System .nanoTime () - start ;
531
- circuitBreaker .onError (durationInNanos , throwable );
532
- throw throwable ;
538
+ circuitBreaker .onError (durationInNanos , exception );
539
+ throw exception ;
533
540
}
534
541
};
535
542
}
@@ -551,10 +558,11 @@ static <T> Consumer<T> decorateConsumer(CircuitBreaker circuitBreaker, Consumer<
551
558
consumer .accept (t );
552
559
long durationInNanos = System .nanoTime () - start ;
553
560
circuitBreaker .onSuccess (durationInNanos );
554
- } catch (Throwable throwable ) {
561
+ } catch (Exception exception ) {
562
+ // Do not handle java.lang.Error
555
563
long durationInNanos = System .nanoTime () - start ;
556
- circuitBreaker .onError (durationInNanos , throwable );
557
- throw throwable ;
564
+ circuitBreaker .onError (durationInNanos , exception );
565
+ throw exception ;
558
566
}
559
567
};
560
568
}
@@ -576,10 +584,11 @@ static <T> CheckedConsumer<T> decorateCheckedConsumer(CircuitBreaker circuitBrea
576
584
consumer .accept (t );
577
585
long durationInNanos = System .nanoTime () - start ;
578
586
circuitBreaker .onSuccess (durationInNanos );
579
- } catch (Throwable throwable ) {
587
+ } catch (Exception exception ) {
588
+ // Do not handle java.lang.Error
580
589
long durationInNanos = System .nanoTime () - start ;
581
- circuitBreaker .onError (durationInNanos , throwable );
582
- throw throwable ;
590
+ circuitBreaker .onError (durationInNanos , exception );
591
+ throw exception ;
583
592
}
584
593
};
585
594
}
@@ -600,10 +609,11 @@ static Runnable decorateRunnable(CircuitBreaker circuitBreaker, Runnable runnabl
600
609
runnable .run ();
601
610
long durationInNanos = System .nanoTime () - start ;
602
611
circuitBreaker .onSuccess (durationInNanos );
603
- } catch (Throwable throwable ){
612
+ } catch (Exception exception ){
613
+ // Do not handle java.lang.Error
604
614
long durationInNanos = System .nanoTime () - start ;
605
- circuitBreaker .onError (durationInNanos , throwable );
606
- throw throwable ;
615
+ circuitBreaker .onError (durationInNanos , exception );
616
+ throw exception ;
607
617
}
608
618
};
609
619
}
@@ -626,10 +636,11 @@ static <T, R> Function<T, R> decorateFunction(CircuitBreaker circuitBreaker, Fun
626
636
long durationInNanos = System .nanoTime () - start ;
627
637
circuitBreaker .onSuccess (durationInNanos );
628
638
return returnValue ;
629
- } catch (Throwable throwable ){
639
+ } catch (Exception exception ){
640
+ // Do not handle java.lang.Error
630
641
long durationInNanos = System .nanoTime () - start ;
631
- circuitBreaker .onError (durationInNanos , throwable );
632
- throw throwable ;
642
+ circuitBreaker .onError (durationInNanos , exception );
643
+ throw exception ;
633
644
}
634
645
};
635
646
}
@@ -652,10 +663,11 @@ static <T, R> CheckedFunction1<T, R> decorateCheckedFunction(CircuitBreaker circ
652
663
long durationInNanos = System .nanoTime () - start ;
653
664
circuitBreaker .onSuccess (durationInNanos );
654
665
return returnValue ;
655
- } catch (Throwable throwable ){
666
+ } catch (Exception exception ){
667
+ // Do not handle java.lang.Error
656
668
long durationInNanos = System .nanoTime () - start ;
657
- circuitBreaker .onError (durationInNanos , throwable );
658
- throw throwable ;
669
+ circuitBreaker .onError (durationInNanos , exception );
670
+ throw exception ;
659
671
}
660
672
};
661
673
}
0 commit comments