简体   繁体   English

获取 TypeError:在发送 ajax 请求(Angular 12)时无法读取未定义的属性(读取“管道”)

[英]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.

相关问题 错误:无法读取未定义的属性(读取“管道”)Angular12 - Error: Cannot read properties of undefined (reading 'pipe') Angular12 Angular 12:错误类型错误:无法读取未定义的属性(读取“nativeElement”) - Angular 12: ERROR TypeError: Cannot read properties of undefined (reading 'nativeElement') 错误类型错误:无法读取未定义的属性(读取“管道”) - ERROR TypeError: Cannot read properties of undefined (reading 'pipe') Angular 12 - 无法读取未定义的属性(读取“值”) - Angular 12 - Cannot read properties of undefined (reading 'values') Angular 7:TypeError:无法读取未定义的属性(读取“substr”) - Angular 7: TypeError: Cannot read properties of undefined (reading 'substr') 处理 gulp 文件时我无法摆脱这个问题 TypeError: Cannot read properties of undefined (reading &#39;pipe&#39;) - I can't get rid of this problem while working with gulp file TypeError: Cannot read properties of undefined (reading 'pipe') 运行获取时:TypeError:无法读取未定义的属性(读取“发送”) - When running getting: TypeError: Cannot read properties of undefined (reading 'send') 在 reactjs TypeError 中出现错误:无法读取未定义的属性(读取“过滤器”) - Getting error in reactjs TypeError: Cannot read properties of undefined (reading 'filter') 我在 React 中收到“TypeError: Cannot read properties of undefined(reading: 0)” - I'm getting "TypeError: Cannot read properties of undefined(reading: 0)" in React 类型错误:无法读取未定义的属性(读取“createdTimestamp”) - TypeError: Cannot read properties of undefined (reading 'createdTimestamp')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM