0

I'm trying to access the HttpHeaders from an HttpErrorResponse but I cannot see all the headers, am I using the HttpClient incorrectly or is this an Angular bug: Sample demonstrating the problem

I can see in the developer tools that there should be the following header WWW-Authenticate:Bearer realm="spotify" however it is not present.

Mark
  • 2,392
  • 4
  • 21
  • 42
  • Read the documentation: https://angular.io/guide/http#reading-the-full-response – Eliseo Dec 21 '17 at 12:08
  • 1
    I have read the documentation and that is for getting the full response in the happy path not the error response I have already tried adding {observe: 'response'} and it just changes the normal response type: https://embed.plnkr.co/EDLjgWUjrXkNm3uNpgRl/ Please take more than two minutes before down voting! – Mark Dec 21 '17 at 12:42

1 Answers1

1

I encountered a similar issue with the eTag header : this is a Cross Origin issue.

From what I remember, CORS return only a couple of simple headers, such as Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, etc.

If you want to return a specific header, you have to add another header, Access-Control-Expose-Headers, containing a list of the headers you want to return with it. So, in your case, Access-Control-Expose-Headers = 'WWW-Authenticate'.

You also obvioulsy need to change your backend to return the same header to Angular.

Hope this helps !

  • It sounds like it might be the right track however I wonder why I only see Content-Type by default – Mark Dec 21 '17 at 12:49
  • `From what I remember, CORS return only a couple of simple headers, such as Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, etc.` –  Dec 21 '17 at 12:52
  • Seems like Content-Type is one of them :P –  Dec 21 '17 at 12:52
  • 2
    https://stackoverflow.com/a/47884516/6294072 ... https://stackoverflow.com/a/47815462/6294072 Choose the best question and mark others as duplicates if you feel they are. https://meta.stackexchange.com/questions/10841/how-should-duplicate-questions-be-handled – AT82 Dec 22 '17 at 13:20