當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Observable.catch方法代碼示例

本文整理匯總了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);
   });
 }
開發者ID:kensodemann,項目名稱:time-trax,代碼行數:8,代碼來源:time-trax-http.service.ts

示例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);
      }
    });

  }
開發者ID:mmrath,項目名稱:ng-cli-webpack-test,代碼行數:11,代碼來源:http-interceptor.ts

示例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);
     }
   });
 }
開發者ID:Boychenko,項目名稱:sample-todo-2016,代碼行數:11,代碼來源:httpInterceptor.ts

示例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);
     }
   });
 }
開發者ID:mmrath,項目名稱:base-app-dashboard,代碼行數:11,代碼來源:http-interceptor.ts

示例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);
         }
     });
 }
開發者ID:austinmaclean,項目名稱:faithinquest,代碼行數:12,代碼來源:httpErrorHandlerService.ts

示例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);
            }
        });
    }
開發者ID:lexon0011,項目名稱:IssueDemonstrator,代碼行數:12,代碼來源:httpInterceptor.ts

示例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);
            }
        });

    }
開發者ID:androidzhaoxiaogang,項目名稱:angular2-oauth2-swagger2,代碼行數:12,代碼來源:http.interceptor.ts

示例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);
      }
    });

  }
開發者ID:enyachoke,項目名稱:SavannahAcademia,代碼行數:12,代碼來源:http.ts

示例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);
        }
      });

    }
開發者ID:sergio11,項目名稱:instangular,代碼行數:14,代碼來源:httpclient.service.ts

示例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;
				}
			});
	}
開發者ID:AntonGrigoriev,項目名稱:3group,代碼行數:18,代碼來源:CustomHttp.ts


注:本文中的rxjs/Observable.Observable.catch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。