本文整理汇总了TypeScript中rxjs.Observable.catch方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.catch方法的具体用法?TypeScript Observable.catch怎么用?TypeScript Observable.catch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs.Observable
的用法示例。
在下文中一共展示了Observable.catch方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: intercept
private intercept(observable: Observable<Response>): Observable<Response> {
return observable.catch((err, source) => {
if( err.status == 401 ) {
// Do something about error
return Observable.empty();
}
return Observable.throw(err);
});
}
示例2: intercept
intercept(observable: Observable<Response>): Observable<Response> {
return observable.catch((err, source) => {
if (err.status == 401) {
//this._router.navigate(['/login']);
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) && !_.includes(err.url, 'app/auth/login') && !_.includes(err.url, 'app/auth/activate/by/key')) {
localStorage.removeItem('user_id');
localStorage.removeItem('name');
this.router.navigate(['']);
return Observable.empty();
} else {
return Observable.throw(err);
}
});
}
示例4: intercept
private intercept(observable: Observable<Response>, errorHandler: DefaultErrorHandler): Observable<Response> {
return observable.catch((err, source) => {
if (err.status === 401) {
this.authService.logout();
return Observable.empty();
}
if (err.status === 500) {
if (!errorHandler) {
errorHandler = new DefaultErrorHandler(this.injector);
}
errorHandler.handle({
caption: 'Error Occurred',
message: 'Something went wrong. Please try again or contact your administrator.',
details: err.json().stackTrace,
errorCode: err.json().errorCode,
});
}
return Observable.throw(err.json());
});
}