I'd like to be able to handle any errors that error when calling this.authService.refreshToken(). Can errors be handled within the switchmap block, or how do I go about handling an error in this case?
post3(endpoint: string, body: string) : Observable<any> {
if (this.authService.tokenRequiresRefresh()) {
this.authService.tokenIsBeingRefreshed.next(true);
return this.authService.refreshToken().switchMap(
data => {
this.authService.refreshTokenSuccessHandler(data);
if (this.authService.loggedIn()) {
this.authService.tokenIsBeingRefreshed.next(false);
return this.postInternal(endpoint, body);
} else {
this.authService.tokenIsBeingRefreshed.next(false);
this.router.navigate(['/sessiontimeout']);
Observable.throw(data);
}
}
);
}
else {
return this.postInternal(endpoint, body);
}
}
return Observable.throw(data);