本文整理匯總了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);
}
}