@@ -34,8 +34,7 @@ public void monoShouldEmitAFallbackValueOnError() {
34
34
35
35
String recoveryValue = "Recovered!" ;
36
36
37
- // TODO: Replace this line with a fallback value in an error happens
38
- Mono <String > withErrorHandling = failedMono ;
37
+ Mono <String > withErrorHandling = failedMono .onErrorReturn (recoveryValue );
39
38
40
39
StepVerifier .create (withErrorHandling ).expectNext ("Recovered!" ).verifyComplete ();
41
40
}
@@ -47,8 +46,7 @@ public void monoShouldEmitADeferredFallbackValueOnError() {
47
46
48
47
Mono <String > recoveryValue = Mono .just ("Recovered!" );
49
48
50
- // TODO: Replace this line with a fallback that is computed in a deferred way
51
- Mono <String > withErrorHandling = failedMono ;
49
+ Mono <String > withErrorHandling = failedMono .onErrorResume (t -> recoveryValue );
52
50
53
51
StepVerifier .create (withErrorHandling ).expectNext ("Recovered!" ).verifyComplete ();
54
52
}
@@ -60,8 +58,7 @@ public void monoShouldEmitAFallbackValueIfEmpty() {
60
58
61
59
Mono <String > recoveryValue = Mono .just ("Recovered!" );
62
60
63
- // TODO: Replace this line with a fallback that is computed in a deferred way
64
- Mono <String > withErrorHandling = emptyMono ;
61
+ Mono <String > withErrorHandling = emptyMono .switchIfEmpty (recoveryValue );
65
62
66
63
StepVerifier .create (withErrorHandling ).expectNext ("Recovered!" ).verifyComplete ();
67
64
}
@@ -71,8 +68,7 @@ public void monoShouldTranslateException() {
71
68
72
69
Mono <String > failedMono = Mono .error (new IllegalStateException ("Something bad happened!" ));
73
70
74
- // TODO: Replace this line with a Mono translating IllegalStateException to MyBusinessException
75
- Mono <String > withErrorHandling = failedMono ;
71
+ Mono <String > withErrorHandling = failedMono .onErrorMap (MyBusinessException ::new );
76
72
77
73
StepVerifier .create (withErrorHandling ).expectError (MyBusinessException .class ).verify ();
78
74
}
0 commit comments