本文整理汇总了TypeScript中rxjs/operators/catchError.catchError函数的典型用法代码示例。如果您正苦于以下问题:TypeScript catchError函数的具体用法?TypeScript catchError怎么用?TypeScript catchError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了catchError函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: readRequest
protected readRequest(state: State): Observable<HttpResponse<Object>> {
return this.getDataSource().pipe(
switchMap(dataSource => dataSource.read(this.getFilterOptions(state))),
map(data => this.parseDSResponse(data)),
catchError((error, retry) => _throw(this.getErrorResponse(error)))
);
}
示例2: switchMap
switchMap((action: ActionStockMarketRetrieve) =>
this.service
.retrieveStock(action.payload.symbol)
.pipe(
map(stock => new ActionStockMarketRetrieveSuccess({ stock })),
catchError(error =>
of(new ActionStockMarketRetrieveError({ error }))
)
)
示例3:
resolveFn: (catalog: CatalogService, state: StateService, loading: TdLoadingService) => {
loading.register(ConnectorComponent.LOADER);
return catalog.getConnector(state.transition.params().connectorId)
.pipe(finalize(() => loading.resolve(ConnectorComponent.LOADER)))
.pipe(catchError(() => {
return state.go("catalog.connectors")
}))
.toPromise();
}
示例4: handleOperation
protected handleOperation(operation: (dataSource: DataSource) => void): Observable<any> {
return this.getDataSource().pipe(
switchMap(dataSource => {
operation(dataSource);
return dataSource.saveChanges();
}),
catchError((error, retry) => _throw(this.getErrorResponse(error)))
);
}
示例5: switchMap
switchMap(action =>
this.service.retrieveStock(action.payload).pipe(
map(stock => ({
type: STOCK_MARKET_RETRIEVE_SUCCESS,
payload: stock
})),
catchError(err =>
of({ type: STOCK_MARKET_RETRIEVE_ERROR, payload: err })
)
)
示例6: intercept
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const accessToken = this.tokenStoreService.getRawAuthToken(AuthTokenType.AccessToken);
if (accessToken) {
request = request.clone({
headers: request.headers.set("Authorization", `Bearer ${accessToken}`)
});
return next.handle(request).pipe(
catchError((error: any, caught: Observable<HttpEvent<any>>) => {
console.error({ error, caught });
if (error.status === 401 || error.status === 403) {
this.router.navigate(["/accessDenied"]);
}
return ErrorObservable.create(error);
})
);
} else {
// login page
return next.handle(request);
}
}