How to cancel current request in interceptor - Angular 4

后端 未结 7 2018
情书的邮戳
情书的邮戳 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 01:58

    As suggested above, there is more optimal way to handle the error with custom response

    import { throwError, Observable } from 'rxjs';
    import { HttpEvent } from '@angular/common/http';
    
    intercept(request: HttpRequest, next: HttpHandler): Observable> {
      if (authFailedDummy(request)) {
        return throwError(new Error('Authorization error: The request did not go through'));
      }
      return next.handle(request);
    }
    

提交回复
热议问题