2

After a long search I keep getting the same answer that this seems to be correct:

  intercept(request: HttpRequest<any>, next: HttpHandler): 
  Observable<HttpEvent<any>> {
    return next.handle(request).catch(errorResponse => {
      const status = errorResponse.status;
      if (status === 401) { this.matDialog.open(UserDialogComponent); }

      return Observable.throw(status);
    });
  }

This however gives the following error:

ERROR Error: Uncaught (in promise): 401 at S (polyfills.8847e333380b2b4c3385.bundle.js:1) ...

Besides the:

polyfills.8847e333380b2b4c3385.bundle.js:1 GET http://localhost:8080/users/auth 401 (Unauthorized)

error.

The 401 is intentional to test my error handling.

Is this the expected and only handling of Http errors with interceptors in Angular, or can I catch this error somehow?

Many thanks in advance.

1 Answer 1

2

For anyone still interested in the answer:

Turns out it was a route guard somewhere else in the project that did not .catch the subscription.

So this is not normal behavior and should be investigate further.

Sign up to request clarification or add additional context in comments.

1 Comment

The problem for was that I had in my cache old data, because of having multiple credentials tests on the same localhost for different projects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.