I need some help. I would to get the value of response header for get some error information.
There is the contain of response header:
HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
Access-Control-Expose-Headers: X-Total-Pages, X-Page
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: PUT, POST, GET, OPTIONS, DELETE
Access-Control-Allow-Headers: Content-Type
Access-Control-Max-Age: 3600
ErrorMessage: entity.name.error
Content-Length: 0
Date: Tue, 23 Jun 2015 18:00:34 GMT
Connection: close
Request header:
PUT /api/ComponentType HTTP/1.1
Host: localhost:9000
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: application/json, text/plain, */*
Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/json;charset=utf-8
Content-Length: 44
Origin: null
Connection: keep-alive
I would to get the error message.
Actually there is my resource:
angular.module('MyAPP')
.factory('ComponentTypeRsc', function ($resource, AppCST) {
return $resource(AppCST.API_URL + ':' + AppCST.API_PORT +'/api/ComponentType/:id', {}, {
'query': { method: 'GET', isArray: true},
'get': {
method: 'GET',
transformResponse: function (data, headers) {
data = angular.fromJson(data);
return data
}
},
'update': { method:'PUT',
transformResponse: function(data, headers){
//MESS WITH THE DATA
response = {}
response.data = data;
response.headers = headers();
return response;
},
inteceptor: {
responseError : resourceErrorHandler,
response : resourceErrorHandler
}
}
});
function resourceErrorHandler(response) {
console.log(response);
}
});
And my controller:
ComponentTypeRsc.update($scope.componentType, function(res, header) {
$scope.debugCreateOk=res;
$scope.componentTypes = ComponentTypeSvc.loadAll();
$('#saveComponentTypeModal').modal('hide');
// ajoute au tableau le nouvel élement.
// componentTypes.push({id: $scope.componentType.name });
$scope.clear();
}, function(error) {
console.log('error start');
$scope.debugCreateError = error;
console.log('error end');
});
Like you can see the value of $scope.debugCreateError doesn't contain ErrorMessage
How can I perform that ? Thanks for help