The following code effectively maps promise resolution to true
and a promise error to false
.
onlineUpdate$
.switchMap(online => {
switch (online) {
default:
case true: {
const connected$ = new Rx.Subject();
axios.get("/some/url/to/test/connection")
.then(response => connected$.next(true))
.catch(error => connected$.next(false));
return connected$;
}
case false: {
return Rx.Observable.of(false);
}
}
});
But something about creating the intermediate Rx.Subject
feels like I'm doing more work than I need to. Is there a more elegant or built-in way to map promise resolution to one value and promise error to another without the use of an intermediate Rx.Subject
or other observable?