1

I am building a simple angular 1.4.8 app that talks to a RESTful API. A user can add an item which POSTs to the REST API using $http. The API can respond with 201 created, or in case a similar item already exists with 409 status and a Location header indicating the existing item's ID.

In my app, to handle the case where an item exists I use the catch handler of the httpPromise, but I can't access the Location header there. In chrome dev tools, I see the POST request and 409 response with the Location header (Just to prove that it is there). While debugging, in the catch handler I inspect the function's argument and see the status 409, and a headers function, but the only header present is content-type, the Location header is missing.

How can I access the Location header from the httpPromise's response argument?

EDIT: Here you can see the request\response in the Network tab with the Location header:

enter image description here

Here you can see the piece of code that should look at the header and in the console the fact that the Location header is missing:

enter image description here

itaysk
  • 5,852
  • 2
  • 33
  • 40
  • If you can't access the Location header, it's probably that it isn't there. Check your server. Also check the network panel of your browser dev tools to see what the response actually looks like. It's always better to post your code rather than describing it. We can spot bugs in code, but it's much more difficult to spot a bug in a description. – JB Nizet Aug 01 '16 at 21:14
  • updated with more details – itaysk Aug 01 '16 at 21:37

1 Answers1

0

Found the solution here. The issue was that the app ran under a different domain then the server, so adding Access-Control-Expose-Headers fixed it.

Community
  • 1
  • 1
itaysk
  • 5,852
  • 2
  • 33
  • 40