本文整理汇总了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()))
);
}
示例2:
.catch((error: Response | any) => {
if (error instanceof Response && error.status === 404) {
return Observable.throw(LoadError.createNotExistsError());
} else {
return Observable.throw(LoadError.createGeneralError());
}
});
示例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);
}
示例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 });
})));
示例5: handleError
private handleError(errorResponse: Response) {
let body = errorResponse.json();
let message = body.message ?
body.message :
(errorResponse.statusText || 'unknown error');
return Observable.throw(message);
}
示例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;
});
}
示例7: _extractData
protected _extractData(res:Response):Observable<Object> {
let body = res.json();
if (body.errno) {
return Observable.throw(body);
}
return Observable.of(body.data);
}
示例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')
});
示例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);
}
示例10: _handleError
private _handleError(response: Response): Observable<any> {
if(response.status === 500) {
return Observable.of(null)
} else {
return Observable.throw(response);
}
}