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