当前位置: 首页>>代码示例>>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;未经允许,请勿转载。