Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
balamaci committed Nov 10, 2016
1 parent a9d6398 commit 7a5baaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,8 @@ private Flux<String> simulateRemoteOperation(String color) {
### onErrorReturn

The 'onErrorReturn' operator replaces an exception with a value:


```
Flux<String> colors = Flux.just("green", "blue", "red", "white", "blue")
.flatMap(color -> simulateRemoteOperation(color))
Expand Down Expand Up @@ -739,8 +741,8 @@ returns:
22:15:51 [main] INFO - Subscriber got Completed event
```

### onErrorResumeNext
onErrorResumeNext() returns a stream instead of an exception, useful for example to invoke a fallback
### onErrorResumeWith
onErrorResumeWith() returns a stream instead of an exception, useful for example to invoke a fallback
method that returns also a stream

```
Expand Down
20 changes: 14 additions & 6 deletions src/test/java/com/balamaci/reactor/Part08ErrorHandling.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,20 @@ public void errorIsTerminalOperation() {


/**
* The 'onErrorReturn' operator doesn't prevent the unsubscription from the 'colors'
* but it does translate the exception for the downstream operators and the final Subscriber
* receives it in the 'onNext()' instead in 'onError()'
* The 'onErrorReturn' operator doesn't prevent the unsubscription from the 'numbers'
* and 'colors' stream of the map operator, but it does translate the exception
* for the downstream operators and the final Subscriber which receives it in the 'onNext()'
* instead in 'onError()'
*/
@Test
public void onErrorReturnDoesntPrevent() {
public void onErrorReturnDoesntPreventUnsubscription() {
Flux<Integer> numbers = Flux.just("1", "3", "a", "4", "5", "c")
.map(Integer::parseInt) //parseInt throws NumberFormatException
.onErrorReturn(0); //for non numeric values like "a", "c"
subscribeWithLog(numbers);

log.info("Another stream");

Flux<String> colors = Flux.just("green", "blue", "red", "yellow", "blue")
.map(color -> {
if ("red".equals(color)) {
Expand Down Expand Up @@ -86,11 +94,11 @@ public void onErrorReturnWithFlatMap() {


/**
* onErrorResumeNext() returns a stream instead of an exception, useful for example
* onErrorResumeWith() returns a stream instead of an exception, useful for example
* to invoke a fallback method that returns also a stream
*/
@Test
public void onErrorResumeNext() {
public void onErrorResumeWith() {
Flux<String> colors = Flux.just("green", "blue", "red", "white", "blue")
.flatMap(color -> simulateRemoteOperation(color)
.onErrorResumeWith(th -> {
Expand Down

0 comments on commit 7a5baaf

Please sign in to comment.