本文整理匯總了TypeScript中rxjs/internal/operators.catchError函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript catchError函數的具體用法?TypeScript catchError怎麽用?TypeScript catchError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了catchError函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: intercept
/**
* 攔截器 給請求設置 authorization 的頭
* @param {HttpRequest<any>} req
* @param {HttpHandler} next
* @description
* @returns {Observable<HttpEvent<any>>}
*/
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// 攔截請求
let token = '43aaedb78c2ef89bb9ac1cd5f5f22ec'; // 獲取token
let authReq = null;
if (token) {
authReq = req.clone({setHeaders: {Authorization: token}});
}
if (req.url === '/business/topology/static/export') {
authReq = authReq.clone({setHeaders: {'Content-Type': 'form-data'}});
}
return next.handle(authReq || req).pipe(mergeMap((event: any) => {
if (event instanceof HttpResponse && event.status !== 200) {
return Observable.create(observer => observer.next(event));
}
return Observable.create(observer => observer.next(event)); // 獲取成功的
}),
catchError((err: HttpResponse<any>, caught: Observable<any>) => { // 返回異常
if (err.status === 401) {
this.confirmSrv.warning({
nzTitle: '提示',
nzContent: '登錄超時,請重新登錄!',
nzOnOk: () => { }
});
}
return Observable.create(observer => observer.next(event));
})
);
}
示例2: getFoodRegistrations
public getFoodRegistrations(fromDate: Moment = null, toDate: Moment = null, slot: number = null) {
const url = this.apiService.getApiUrl('/food-registrations');
let params = new HttpParams();
if (fromDate != null) {
params = params.append('from', this.dates.toLink(fromDate));
}
if (toDate != null) {
params = params.append('to', this.dates.toLink(toDate));
}
if (slot != null) {
params = params.append('slot', slot.toString());
}
return this.http.get<FoodRegistration[]>(url, {params}).pipe(
catchError(this.handleError)
);
}
示例3: execAndWaitForOutputToMatch
export function execAndWaitForOutputToMatch(cmd: string, args: string[], match: RegExp) {
if (cmd === 'ng' && args[0] === 'serve') {
// Accept matches up to 20 times after the initial match.
// Useful because the Webpack watcher can rebuild a few times due to files changes that
// happened just before the build (e.g. `git clean`).
// This seems to be due to host file system differences, see
// https://nodejs.org/docs/latest/api/fs.html#fs_caveats
return concat(
from(
_exec({ waitForMatch: match }, cmd, args)
),
defer(() => waitForAnyProcessOutputToMatch(match, 2500)).pipe(
repeat(20),
catchError(() => EMPTY),
),
).pipe(
takeLast(1),
).toPromise();
} else {
return _exec({ waitForMatch: match }, cmd, args);
}
}
示例4: registerFood
public registerFood(food: FoodRegistration) {
const url = this.apiService.getApiUrl('/food-registrations');
return this.http.post<{}>(url, food).pipe(
catchError(this.handleError)
);
}
示例5: getFoodKinds
public getFoodKinds() {
const url = this.apiService.getApiUrl('/food-kinds');
return this.http.get<FoodKind[]>(url).pipe(
catchError(this.handleError)
);
}
示例6: login
public login(username: string, password: string) {
const url = this.apiService.getApiUrl('/login');
return this.http.post(url, {username, password}).pipe(
catchError(this.handleError)
);
}
示例7: getFoodTypes
public getFoodTypes(foodKindId: number) {
const url = this.apiService.getApiUrl(`/food-kinds/${foodKindId}/food-types`);
return this.http.get<FoodType[]>(url).pipe(
catchError(this.handleError)
);
}