本文整理汇总了TypeScript中rxjs/internal/observable/throwError.throwError函数的典型用法代码示例。如果您正苦于以下问题:TypeScript throwError函数的具体用法?TypeScript throwError怎么用?TypeScript throwError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了throwError函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should not decrease quantity on error retrieving basket item and log the error', fakeAsync(() => {
basketService.get.and.returnValue(throwError('Error'))
console.log = jasmine.createSpy('log')
component.dec(1)
expect(console.log).toHaveBeenCalledWith('Error')
expect(basketService.put).not.toHaveBeenCalled()
}))
示例2: concatMap
concatMap(chapter => {
if (chapter === 3) {
return throwError(new Error('Forced error!'));
} else {
return story.getChapter(chapter);
}
}),
示例3: handleError
private handleError(errResp: HttpErrorResponse | any) {
let errMsg: any;
if (errResp instanceof HttpErrorResponse) {
switch (errResp.status) {
case 401:
// handle Unauthorized error and redirect to login page
errMsg = '401 Unauthorized';
console.log(this.router.url);
if (this.router.url !== '/login') {
this.router.navigate(['/login']);
}
break;
case 403:
errMsg = '403 Forbidden';
console.log();
if (errResp.error['code'] === 1) {
this.router.navigate(['/login']);
} else {
this.message.warning('没有权限');
}
break;
default:
// this.message.error('请求错误');
break;
}
} else {
errMsg = 'Request Error';
}
return throwError(errResp.error as HttpError);
}
示例4: it
it('should give an error if FeedbackService fails to delete feedback', fakeAsync(() => {
feedbackService.del.and.returnValue(throwError('Error'))
component.deleteFeedback(1)
tick()
expect(component.error).toBe('Error')
}))
示例5: it
it('should show an error if indices could not be activated', () => {
const service = fixture.debugElement.injector.get(IndexService);
indexServiceStub.setActive.and.returnValue(throwError('fake error'));
fixture.detectChanges();
shouldShowError(element, 'fake error');
});