我正从5号角迁移到6号角,我还不太清楚新的管道运算符语法。
考虑我的角度5 http拦截器
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
this.request = req;
//do stuff
return next.handle(this.request)
.do(event => {
//do logging stuff
},
err => {
//do error stuff
});
}
这是我尝试将其转换为pipe
方式
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
this.request = req;
//do stuff
return next.handle(this.request).pipe(
tap(event => {
//do logging stuff
},
err => {
//do error stuff
}));
}
但是,这不能编译-使用pipe
函数的整个过程都带有以下错误。
Severity Code Description Project File Line Suppression State
Error TS2345 (TS) Argument of type 'MonoTypeOperatorFunction<{}>' is not
assignable to parameter of type 'UnaryFunction<Observable<HttpEvent<any>>,
Observable<any>>'.
Types of parameters 'source' and 'source' are incompatible.
Type 'Observable<HttpEvent<any>>' is not assignable to type
'Observable<{}>'.
Property 'source' is protected in type 'Observable<HttpEvent<any>>' but public in type 'Observable<{}>'. C:\Users\stas.levich\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\stas.levich\Documents\Projects\EEA.Projects\DEP\MassAir\Web\src\app\services\httpinterceptor.service.ts 44 Active
答案 0 :(得分:0)
<mappers>
<mapper resource="mappers/account.xml" />
</mappers>
需要一组运算符。 pipe
是运算符。 tap
函数不是是有效的RxJs运算符。尝试err =>
这是我的一种get方法的示例:
catchError
答案 1 :(得分:0)
尝试以下代码:
return next.handle(authReq).pipe(
tap(event => {
return event;
}),
catchError(error => {
// On Error
}),
finalize(() => {
// on finalize
})
);