本文整理汇总了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));
})
);
}
开发者ID:zmlovelin,项目名称:tools,代码行数:35,代码来源:noop-interceptor.ts
示例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)
);
}
开发者ID:PIWEEK,项目名称:comocomo,代码行数:16,代码来源:food-registrations-api.service.ts
示例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);
}
}
开发者ID:nickroberts,项目名称:angular-cli,代码行数:22,代码来源:process.ts
示例4: registerFood
public registerFood(food: FoodRegistration) {
const url = this.apiService.getApiUrl('/food-registrations');
return this.http.post<{}>(url, food).pipe(
catchError(this.handleError)
);
}
开发者ID:PIWEEK,项目名称:comocomo,代码行数:6,代码来源:food-registrations-api.service.ts
示例5: getFoodKinds
public getFoodKinds() {
const url = this.apiService.getApiUrl('/food-kinds');
return this.http.get<FoodKind[]>(url).pipe(
catchError(this.handleError)
);
}
开发者ID:PIWEEK,项目名称:comocomo,代码行数:6,代码来源:food-kinds-api.service.ts
示例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)
);
}
开发者ID:PIWEEK,项目名称:comocomo,代码行数:6,代码来源:users-api.service.ts
示例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)
);
}
开发者ID:PIWEEK,项目名称:comocomo,代码行数:6,代码来源:food-types-api.service.ts
注:本文中的rxjs/internal/operators.catchError函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论