我需要一些帮助。 我会得到响应头的值来获取一些错误信息。
包含响应标头:
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
请求标题:
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
我会收到错误消息。
实际上有我的资源:
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);
}
});
我的控制员:
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');
});
就像你可以看到$ scope.debugCreateError的值不包含ErrorMessage
我该怎么做? 谢谢你的帮助