{"action":"created","issue":{"url":"https://api.github.com/repos/ReactiveX/rxjs/issues/1928","repository_url":"https://api.github.com/repos/ReactiveX/rxjs","labels_url":"https://api.github.com/repos/ReactiveX/rxjs/issues/1928/labels{/name}","comments_url":"https://api.github.com/repos/ReactiveX/rxjs/issues/1928/comments","events_url":"https://api.github.com/repos/ReactiveX/rxjs/issues/1928/events","html_url":"https://github.com/ReactiveX/rxjs/pull/1928","id":175829387,"number":1928,"title":"feat(onErrorReturn): Add new Observable.prototype.onErrorReturn operator","user":{"login":"jayphelps","id":762949,"avatar_url":"https://avatars.githubusercontent.com/u/762949?v=3","gravatar_id":"","url":"https://api.github.com/users/jayphelps","html_url":"https://github.com/jayphelps","followers_url":"https://api.github.com/users/jayphelps/followers","following_url":"https://api.github.com/users/jayphelps/following{/other_user}","gists_url":"https://api.github.com/users/jayphelps/gists{/gist_id}","starred_url":"https://api.github.com/users/jayphelps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jayphelps/subscriptions","organizations_url":"https://api.github.com/users/jayphelps/orgs","repos_url":"https://api.github.com/users/jayphelps/repos","events_url":"https://api.github.com/users/jayphelps/events{/privacy}","received_events_url":"https://api.github.com/users/jayphelps/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-09-08T18:36:39Z","updated_at":"2016-09-08T19:39:49Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ReactiveX/rxjs/pulls/1928","html_url":"https://github.com/ReactiveX/rxjs/pull/1928","diff_url":"https://github.com/ReactiveX/rxjs/pull/1928.diff","patch_url":"https://github.com/ReactiveX/rxjs/pull/1928.patch"},"body":"Note: RxJS v4 _does **not**_ have this operator either.\r\n\r\nSome Rx implementations contain an `onErrorReturn` operator. http://reactivex.io/documentation/operators/catch.html (scroll down and select it from RxJava list)\r\n\r\n> instructs an Observable to emit a particular item when it encounters an error, and then terminate normally\r\n\r\n![image](https://cloud.githubusercontent.com/assets/762949/18284626/8e5cda00-741f-11e6-8a59-346e8275203b.png)\r\n\r\n> The `onErrorReturn` method 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](http://reactivex.io/RxJava/javadoc/rx/Observable.html#onErrorReturn(rx.functions.Func1))\r\n\r\nThis operator is usually similar to `.catch()` but that it expects your provided selector to return a single _value_ instead of an Observable.\r\n\r\nIn practice this is exactly what people do 99% of the time in redux-observable and _maybe_ in common RxJS usage as well?\r\n\r\n\r\n#### Using .catch()\r\n\r\n```js\r\n// return an Observable\r\n.catch(error => Observable.of({\r\n  type: FETCH_USER_REJECTED,\r\n  payload: error.xhr.response,\r\n  error: true\r\n}))\r\n```\r\n```js\r\nconst fetchUserEpic = action$ =>\r\n  action$.ofType(FETCH_USER)\r\n    .mergeMap(action =>\r\n      ajax.getJSON(`/api/users/${action.payload}`)\r\n        .map(fetchUserFulfilled)\r\n        .catch(error => Observable.of({\r\n            type: FETCH_USER_REJECTED,\r\n            payload: error.xhr.response,\r\n            error: true\r\n        }))\r\n    );\r\n```\r\n\r\n#### Using .onErrorReturn()\r\n```js\r\n// Return a value\r\n.onErrorReturn(error => ({\r\n  type: FETCH_USER_REJECTED,\r\n  payload: error.xhr.response,\r\n  error: true\r\n})\r\n```\r\n```js\r\nconst fetchUserEpic = action$ =>\r\n  action$.ofType(FETCH_USER)\r\n    .mergeMap(action =>\r\n      ajax.getJSON(`/api/users/${action.payload}`)\r\n        .map(fetchUserFulfilled)\r\n        .onErrorReturn(error => ({\r\n            type: FETCH_USER_REJECTED,\r\n            payload: error.xhr.response,\r\n            error: true\r\n        })\r\n    );\r\n```\r\n\r\nOr more likely with action creators:\r\n\r\n```js\r\n.onErrorReturn(error => fetchUserRejected(error.xhr.response))\r\n```\r\n\r\nWe originally started to discuss this here https://github.com/redux-observable/redux-observable/issues/102\r\n\r\nCc/ @blesh "},"comment":{"url":"https://api.github.com/repos/ReactiveX/rxjs/issues/comments/245715487","html_url":"https://github.com/ReactiveX/rxjs/pull/1928#issuecomment-245715487","issue_url":"https://api.github.com/repos/ReactiveX/rxjs/issues/1928","id":245715487,"user":{"login":"BerkeleyTrue","id":6775919,"avatar_url":"https://avatars.githubusercontent.com/u/6775919?v=3","gravatar_id":"","url":"https://api.github.com/users/BerkeleyTrue","html_url":"https://github.com/BerkeleyTrue","followers_url":"https://api.github.com/users/BerkeleyTrue/followers","following_url":"https://api.github.com/users/BerkeleyTrue/following{/other_user}","gists_url":"https://api.github.com/users/BerkeleyTrue/gists{/gist_id}","starred_url":"https://api.github.com/users/BerkeleyTrue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BerkeleyTrue/subscriptions","organizations_url":"https://api.github.com/users/BerkeleyTrue/orgs","repos_url":"https://api.github.com/users/BerkeleyTrue/repos","events_url":"https://api.github.com/users/BerkeleyTrue/events{/privacy}","received_events_url":"https://api.github.com/users/BerkeleyTrue/received_events","type":"User","site_admin":false},"created_at":"2016-09-08T19:39:49Z","updated_at":"2016-09-08T19:39:49Z","body":"Has there been discussion around changing the behavior of catch to accept an observable or a value in the selector?\r\n\r\nI bring this up because my initial confusion around the catch operator came from the fact that promise.catch accepts a new value that continues the promise chain: http://jsbin.com/siqepiduyo/edit?js,console\r\n\r\nThis might reduce confusion of new users. "}}
{"actor":{"display_login":"BerkeleyTrue"}}