Skip to content

Instantly share code, notes, and snippets.

@Ibro
Last active April 29, 2017 05:14
Show Gist options
  • Save Ibro/6d40028327828c692f76179f7f7bf2ac to your computer and use it in GitHub Desktop.
Save Ibro/6d40028327828c692f76179f7f7bf2ac to your computer and use it in GitHub Desktop.
RxJS - Error Handling - Coding Blast - www.codingblast.com
import {Observable} from 'rxjs';
console.log('starting');
Observable
.of('CodingBlast', 'cuteword', 'badword', 'coding', 'blast')
.map(w => {
if (w === 'badword') {
throw new Error('Bad things happen!')
}
return w + ' RxJS';
})
.retryWhen(errors => errors.delay(2000).scan(function (errorCount, err) {
console.log('\n');
console.log('scan inside of retryWhen. Error counter: ', errorCount);
if (errorCount >= 3) {
throw err;
}
return errorCount + 1;
}, 1))
.subscribe(value => console.log(value),
err => console.error('oops, an error!', err),
() => console.log('complete!'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment