I have a custom http service which overrides default angular 2 http service. This service sets custom default options and set loader on request start and hides loader on request completion.
I also want to add, the functionality to redirect user to the login page in case if Unauthorized error (401, 403) is received from server. For example below is my http method
get(url: string, options?: RequestOptionsArgs): Observable<any> {
this.setLoadingStatus();
options = this.prepareOptions(options);
let that = this;
return super.get(url, options)
.map(res => {
this.clearLoadingStatus();
return res.json();
})
.catch(function (err) {
//redirects user to login and display alert
that._gs.alertUnauthorized();
return Observable.empty();
});
}
But when test it in browser i.e. make a request for protected page that returns 401 in case of unauthorized request, it doest redirect to the login page but console displays below error:
GET http://localhost:49547/api/protected/ 401 (Unauthorized)
EXCEPTION: Observable_1.Observable.empty is not a function
ORIGINAL STACKTRACE:
TypeError: Observable_1.Observable.empty is not a function
Can anyone please guide?
super.get().map((res) => {}, (err) => {});syntax?