-1

HttpErrorResponse occurs only in angular terminal output complaining about invalid credentials. But the app works without error in browser, and the http request returns 200. There are no errors in browser console, no errors under network tab as well. The api is using IIS authentication.

this.http.get(this.getUserUrl,
      {
          responseType: 'text',
          withCredentials: true,

      },

enter image description here

1
  • Add all Information as text not as image. Commented Oct 22, 2024 at 4:48

1 Answer 1

1

You might have ssr enabled, so the api call is made on the server.

I'm guessing you are storing the auth token in local storage and on the server window and local storage objects do not use exist.

You can solve this by making sure the api happens only on the client.

...
export class MySpecialComponent {
  isBrowser: boolean;

  constructor( @Inject(PLATFORM_ID) platformId: Object) {
    this.isBrowser = isPlatformBrowser(platformId);
  }

  ngOnInit() {
    if (this.isBrowser) {
      this.someApiCall();
    }
  }
}

You can also solve it using afterNextRender which runs on the browser.

  ngOnInit() {
    afterNextRender(() => {
      this.someApiCall();
    })
  }
Sign up to request clarification or add additional context in comments.

Comments

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.