Created
December 9, 2020 09:46
-
-
Save nfedyashev/3c710bfdda66066f54cb4735614c8a0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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