Skip to content

Instantly share code, notes, and snippets.

@nfedyashev
Created December 9, 2020 09:46
Show Gist options
  • Save nfedyashev/3c710bfdda66066f54cb4735614c8a0c to your computer and use it in GitHub Desktop.
Save nfedyashev/3c710bfdda66066f54cb4735614c8a0c to your computer and use it in GitHub Desktop.
// custom error handling logic
const retryThreeTimes = obs =>
obs.retry(3).catch(_ => Rx.Observable.of('ERROR!'));
const examplePromise = val =>
new Promise(resolve => resolve(`Complete: ${val}`));
//faking request
const subscribe = Rx.Observable.of('some_url')
.mergeMap(url => examplePromise(url))
// could reuse error handling logic in multiple places with let
.let(retryThreeTimes)
//output: Complete: some_url
.subscribe(result => console.log(result));
const customizableRetry = retryTimes => obs =>
obs.retry(retryTimes).catch(_ => Rx.Observable.of('ERROR!'));
//faking request
const secondSubscribe = Rx.Observable.of('some_url')
.mergeMap(url => examplePromise(url))
// could reuse error handling logic in multiple places with let
.let(customizableRetry(3))
//output: Complete: some_url
.subscribe(result => console.log(result));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment