0

I working with $http.get to sent a HTTP request to my web server and retrieve information. I using angular-js version 1.5.8.

This is how my code looks like:

var config = {
    headers: {
        'Authorization': 'Bearer ' + token 
    }
};
$http.get('https://myserver.com/v1/result', config).then(function(response)
{
    // On success
}, function (resposne)
{
    // On error.
    var justForTesting = response.headers('content-type'); // return the expected data ("application/json").
    var code = response.headers('company-error-code'); // Not returning the expected data (11). Actual value - 'null'
});

My problem is to retrieve the header company-error-code from the server's response. Other headers are returning their values without any problems.

In order to make sure that the company-error-code is exists on the server response, I capture the traffic with chrome ("Network" tab) and got this information:

Request URL:https://myserver.com/v1/result
Request Method:GET
Status Code:400 
Remote Address:127.0.0.1:8888
Referrer Policy:no-referrer-when-downgrade
Response Headers
access-control-allow-origin:*
cache-control:no-cache
cf-ray:3d3ccee29b756b55-LHR
content-length:101
content-type:application/json; charset=utf-8
date:Wed, 27 Dec 2017 14:00:47 GMT
expires:-1
pragma:no-cache
server:cloudflare-nginx
status:400
x-aspnet-version:4.0.30319
x-powered-by:ASP.NET
company-error-code:11

As you can see, the header company-error-code:11 is exists on the response (last line in the list) but not when I trying to access it from the response.headers('company-error-code') code.

Why? How to solve it?

No1Lives4Ever
  • 6,430
  • 19
  • 77
  • 140
  • `console.log(response.headers());` return this answer: `{pragma: "no-cache", content-type: "application/json; charset=utf-8", cache-control: "no-cache", expires: "-1"}` – No1Lives4Ever Dec 27 '17 at 14:34
  • `console.log(response.headers('company_error_code'));` return the same asnwer (null). – No1Lives4Ever Dec 27 '17 at 14:35
  • See [MDN Header Reference - `Access-Control-Expose-Headers`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers) – georgeawg Dec 27 '17 at 20:42

0 Answers0