0

I am getting below object by rejection.headers() function in responseerror object of interceptor but unable to get particular header value in angularjs code for example x-request-id value have to store in some variable but unable to do that can any one please suggest,

{pragma: "no-cache", date: "Thu, 06 Sep 2018 14:57:56 GMT", x-content-type-options: "nosniff", x-request-id: "VLCRpt3v", x-frame-options: "DENY", …} cache-control : "no-cache, no-store, max-age=0, must-revalidate" content-type : "application/json;charset=UTF-8" date : "Thu, 06 Sep 2018 14:57:56 GMT" expires : "0" pragma : "no-cache" referrer-policy : "same-origin" transfer-encoding : "chunked" x-content-type-options : "nosniff" x-frame-options : "DENY" x-request-id : "VLCRpt3v" x-xss-protection : "1; mode=block"

and trying below code in angularjs code : var head = rejection.headers(); var requestId = head.x-request-id

1
  • Is this a cross-origin request? Commented Sep 6, 2018 at 15:31

1 Answer 1

2

You'd better create an Interceptor and push it to to $httpProvider interceptor.

Here is what it should look like:

angular.module('app')
      .service('headerRetrieveInterceptor', function ($q) {
        var service = this;
        service.responseError = function (response) {
            // Here Are Your Headers
            console.log(response.headers());

            return $q.reject(response);
        };
    }).config(function($httpProvider) {
        $httpProvider.interceptors.push('headerRetrieveInterceptor');  
})
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.