[英]Getting TypeError: Cannot read properties of undefined (reading 'pipe') while sending ajax request (Angular 12)
I am getting below error while sending ajax request,我在发送 ajax 请求时遇到错误,
ERROR TypeError: Cannot read properties of undefined (reading 'pipe')
at AuthTokenInterceptor.intercept (auth-token.interceptor.ts:43)
auth-token.interceptor.ts auth-token.interceptor.ts
intercept(
request: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
console.log('request', request); // here i am getting request data
// if (accessToken) {
// request = this.getRequestWithToken(request, accessToken);
// }
const handlers = next.handle(request); // but here i am getting undefined
console.log('next.handle(request)', handlers); --> undefined
return handlers.pipe(
catchError((responseError) => {
console.log('authToken responseError', responseError);
if (responseError instanceof HttpErrorResponse) {
} else {
return throwError(responseError);
}
})
);
}
I have data in reuest but getting next.handle(request)
as undefined
;我有数据 reuest 但将next.handle(request)
设为undefined
;
Any help would be appreciated.任何帮助,将不胜感激。 Thanks!谢谢!
next.handle()
returns an Observable. next.handle()
返回一个 Observable。 Angular: Angular:
An interceptor may transform the response event stream as well, by
applying additional RxJS operators on the stream returned by
next.handle().
It's undefined because it is async.它是未定义的,因为它是异步的。 Use a tap
operator to log it.使用tap
操作员记录它。
return handlers.pipe(
tap(res => console.log(res)),
catchError((responseError) => {
console.log('authToken responseError', responseError);
if (responseError instanceof HttpErrorResponse) {
} else {
return throwError(responseError);
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.