本文整理汇总了TypeScript中rxjs/Observable.Observable.catch方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.catch方法的具体用法?TypeScript Observable.catch怎么用?TypeScript Observable.catch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs/Observable.Observable
的用法示例。
在下文中一共展示了Observable.catch方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: redirectIfNotLoggedIn
private redirectIfNotLoggedIn(observable: Observable<Response>): Observable<Response> {
return observable.catch((err, source) => {
if (err.status === 401) {
this.router.navigate(['authentication', 'login']);
}
return Observable.throw(err);
});
}
示例2: intercept
intercept(observable: Observable<Response>): Observable<Response> {
return observable.catch((err, source) => {
if (err.status === 401 && !err.url.endsWith('/api/authentication')) {
//this.store.dispatch(AuthActions.loginFailed(null));
return Observable.empty();
} else {
return Observable.throw(err);
}
});
}
示例3: intercept
intercept(observable: Observable<Response>): Observable<Response> {
return observable.catch((err, source) => {
if (err.status === 401 || err.status === 403
|| err.status === 419 || err.status === 440) {
this._authService.triggerAuth();
return Observable.empty();
} else {
return Observable.throw(err);
}
});
}
示例4: intercept
intercept(observable: Observable<Response>): Observable<Response> {
return observable.catch((err, source) => {
if (err.status === 401 && typeof err.url !== 'undefined' &&
!err.url.endsWith('api/authentication')) {
this.router.navigate(['/login']);
return Observable.empty();
} else {
return Observable.throw(err);
}
});
}
示例5: process
public process(req:Request, observable:Observable<any>):Observable<any> {
return observable.catch((err, source) => {
switch (err.status) {
case ErrorStatus.Unauthorized:
return this.process401();
case ErrorStatus.Forbidden:
return this.process403(err);
default:
return this.processXXX(err, req);
}
});
}
示例6: intercept
intercept(observable: Observable<Response>): Observable<Response> {
return observable.catch((err, source) => {
if (err.status === 401) {
console.error("401 error");
// this.navigator.navigateToLogin({ redirectPath: "sections" });
return Observable.empty();
} else {
return Observable.throw(err);
}
});
}
示例7: intercept
intercept(observable: Observable<Response>): Observable<Response> {
console.log("inside intercept");
return observable.catch((err, source) => {
if (err.status == 401 /*&& !_.endsWith(err.url, 'api/auth/login')*/) {
this._router.navigate(['/login']);
return Observable.empty();
} else {
return Observable.throw(err);
}
});
}
示例8: intercept
intercept(observable: Observable<Response>): Observable<Response> {
console.log('Intercept1=====');
return observable.catch((err, source) => {
if (err.status === 401 && !_.endsWith(err.url, 'authenticate')) {
this._router.go('/login');
return Observable.empty();
} else {
return Observable.throw(err);
}
});
}
示例9: intercept
private intercept(observable: Observable<Response>): Observable<Response> {
console.log("Intercept Http Request");
return observable.catch(res => {
if(res.status === 401){
let router: Router;
router = this.injector.get(Router);
router.navigate(['/signin']);
return Observable.empty();
} else {
return Observable.throw(res);
}
});
}
示例10: wrap
wrap(observable: Observable<Response>, mode: ('json' | 'text' | 'response') = 'json'): Observable<any> {
return observable
.catch(this.errorHandler.bind(this))
.map( (response: Response) => {
switch (mode) {
case 'json':
if(response.text().length) {
return response.json();
} else {
return {};
}
case 'text':
return response.text();
default:
return response;
}
});
}