I would use catchinstead retryWhen, since the latter reproduces the same observable, and the parameters are already set.
, errorHanlder:
export class HttpInterceptor extends Http {
get(url: string, options ? : RequestOptionsArgs): Observable < Response > {
return super.get(url, this.setRequestAuthorizationHeader(options)).catch(errors => this.errorHandler(errors, url, options))
});
}
private setRequestAuthorizationHeader(options ? : RequestOptionsArgs): RequestOptionsArgs {
options.headers.append('Authorization', 'Bearer ' + accessToken);
return options
}
private errorHandler(err: any, url: string, options ? : RequestOptionsArgs) {
if (err.status === 401) {
return this.authenticationService.refreshToken()
.switchMap(data => {
return super.get(url, this.setRequestAuthorizationHeader(options));
});
}
return Observable.throw(err.json());
}
, this.defaultOptions, , , anobservable .