How to cancel current request in interceptor - Angular 4

后端 未结 7 1935
情书的邮戳
情书的邮戳 2021-02-05 01:29

As you know it\'s possible to use Interceptors in new versions of Angular 4.

In mine, I want to cancel a request in interceptor in some conditions. So i

相关标签:
7条回答
  • 2021-02-05 02:15

    I think all you have to do to cut the interceptor chain is to simply return an empty Observable like so:

    import { EMPTY } from 'rxjs';
    
    intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
      if (stopThisRequest) {
        return EMPTY;
      }
    
      return next.handle(request);
    }
    
    0 讨论(0)
提交回复
热议问题