Reputation: 81
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
Upvotes: 0
Views: 1324
Reputation: 602
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');
})
Upvotes: 2