RFC: onErrorReturn() operator
Some Rx implementations contain an onErrorReturn operator. http://reactivex.io/documentation/operators/catch.html (scroll down and select it from RxJava list)
instructs an Observable to emit a particular item when it encounters an error, and then terminate normally

The
onErrorReturnmethod returns an Observable that mirrors the behavior of the source Observable, unless that Observable invokes onError in which case, rather than propagating that error to the observer, onErrorReturn will instead emit a specified item and invoke the observer’s onCompleted method. javadoc
This operator is usually similar to .catch() but that it expects your provided selector to return a single value instead of an Observable.
In practice this is exactly what people do 99% of the time in redux-observable.
Using .catch()
// return an Observable
.catch(error => Observable.of({
type: FETCH_USER_REJECTED,
payload: error.xhr.response,
error: true
}))const fetchUserEpic = action$ =>
action$.ofType(FETCH_USER)
.mergeMap(action =>
ajax.getJSON(`/api/users/${action.payload}`)
.map(fetchUserFulfilled)
.catch(error => Observable.of({
type: FETCH_USER_REJECTED,
payload: error.xhr.response,
error: true
}))
);Using .onErrorReturn()
// Return a value
.onErrorReturn(error => ({
type: FETCH_USER_REJECTED,
payload: error.xhr.response,
error: true
})const fetchUserEpic = action$ =>
action$.ofType(FETCH_USER)
.mergeMap(action =>
ajax.getJSON(`/api/users/${action.payload}`)
.map(fetchUserFulfilled)
.onErrorReturn(error => ({
type: FETCH_USER_REJECTED,
payload: error.xhr.response,
error: true
})
);Or more likely with action creators:
.onErrorReturn(error => fetchUserRejected(error.xhr.response))I've noticed most people don't fully understand what .catch() is doing--that you're returning an observable that should be switched to, on error, which itself may or may not terminate. While .catch() is certainly handy, onErrorReturn on the other hand has more obvious semantics for redux-observable use cases.
This probably belongs in RxJS v5 core, but before I pitch it there I wanted to confirm the community agrees this would be super helpful. Worst case, we can add onErrorReturn to the ActionsObservable prototype, but I'm confident core will want it too.
Cc/ @blesh
Source: redux-observable/redux-observable