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