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


TypeScript Observable.throw方法代碼示例

本文整理匯總了TypeScript中rxjs.Observable.throw方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.throw方法的具體用法?TypeScript Observable.throw怎麽用?TypeScript Observable.throw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rxjs.Observable的用法示例。


在下文中一共展示了Observable.throw方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: rpcPush

    public rpcPush(queueName: string, message: any): Observable<{content: any}> {
        if (!this.connection || !this.channel) {
            return Observable.throw(
                new Error('A connection is required to send messages.')
            );
        }

        if (typeof message !== 'object') {
            return Observable.throw(
                new Error('Message must be a JSON object.')
            );
        }

        const self: RPC_Client = this;

        return Observable.fromPromise<any>(
            new Promise(
                (resolve: Function) => {
                    // Generate message id
                    const correlationId: string = self.generateUuid();

                    // Create listener for response
                    self.responseEmitter.once(correlationId, resolve);

                    // Send message
                    self.sendMessageToQueue.apply(self, [queueName, message, correlationId]);
                }
            )
                .then((msg: Buffer) => JSON.parse(msg.toString()))
        );
    }
開發者ID:db3dev,項目名稱:amqp-rpc-client-controller,代碼行數:31,代碼來源:client.ts

示例2:

 .catch((error: Response | any) => {
     if (error instanceof Response && error.status === 404) {
         return Observable.throw(LoadError.createNotExistsError());
     } else {
         return Observable.throw(LoadError.createGeneralError());
     }
 });
開發者ID:feibeck,項目名稱:fussi,代碼行數:7,代碼來源:player.service.ts

示例3: handleError

 private handleError (error: Response | any) {
   let errMsg: string;
   const body = error.json() || '';
   errMsg = error.message ? error.message : error.toString();
   console.error(errMsg);
   return Observable.throw(body);
 }
開發者ID:mazraara,項目名稱:laravel-angular-admin,代碼行數:7,代碼來源:register.service.ts

示例4: spyOn

            (playerService: PlayerService, pointLogService: PointLogService, router: Router) => {

        spyOn(playerService, 'getPlayer').and.returnValue(
            Observable.throw(LoadError.createGeneralError('foo'))
        );
        spyOn(pointLogService, 'getPointLog').and.returnValue(
            Observable.throw(LoadError.createGeneralError('foo'))
        );
        spyOn(router, 'navigate');

        fixture.detectChanges();
        tick();

        expect(router.navigate).toHaveBeenCalledWith(['/error'], { skipLocationChange: true });

    })));
開發者ID:feibeck,項目名稱:fussi,代碼行數:16,代碼來源:player-detail.component.spec.ts

示例5: handleError

 private handleError(errorResponse: Response) {
     let body = errorResponse.json();
     let message = body.message ?
         body.message :
         (errorResponse.statusText || 'unknown error');
     return Observable.throw(message);
 }
開發者ID:jbhg,項目名稱:staffer,代碼行數:7,代碼來源:people.service.ts

示例6: newUser

  /**
   * Create new user with type player.
   * @param user The user.
   */
  public newUser(user: User): Observable<User> {
    const token = this.login.getToken();
    if (!token) {
      return Observable.throw("No authentication token");
    }

    if (!this.connectivityService.isOnline()) {
      this.storeForLaterPush(user);
      return Observable.from([user]);
    }
    return this.apollo
      .mutate({
        mutation: gql`
          mutation newUser($token: String!, $user: AutoUser!) {
            viewer(token: $token) {
              createAutoUser(user: $user) {
                _id
              }
            }
          }
        `,
        variables: {
          token,
          user,
        },
      }).map(result => {
        return result.data.viewer.createAutoUser as User;
      });
  }
開發者ID:racketometer,項目名稱:frontend-application,代碼行數:33,代碼來源:new-user.service.ts

示例7: _extractData

 protected _extractData(res:Response):Observable<Object> {
   let body = res.json();
   if (body.errno) {
     return Observable.throw(body);
   }
   return Observable.of(body.data);
 }
開發者ID:outsourcingproject,項目名稱:auction_new,代碼行數:7,代碼來源:base.service.ts

示例8:

 .catch(function(error:any){
     console.log("Some error in catch");
     if (error.status === 401 || error.status === 403){
         me.router.navigate(['/logout']);
     }
     return Observable.throw(error || 'Server error')
 });
開發者ID:sayjavajava,項目名稱:Angular-SpringBoot-REST-JWT,代碼行數:7,代碼來源:api-request.service.ts

示例9: handleError

    private handleError(error: any) {

        let errMsg = (error.message) ? error.message :
            error.status ? `${error.status} - ${error.statusText}` : 'Server error';
        console.error(errMsg);
        return Observable.throw(errMsg);
    }
開發者ID:ALjean,項目名稱:eye-fish-frontend,代碼行數:7,代碼來源:WeatherSevice.ts

示例10: _handleError

 private _handleError(response: Response): Observable<any> {
     if(response.status === 500) {
         return Observable.of(null)
     } else {
         return Observable.throw(response);
     }
 }
開發者ID:drewwyatt,項目名稱:observables-demo,代碼行數:7,代碼來源:bar.service.ts


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