dplesa dplesa - 3 months ago 21
reST (reStructuredText) Question

Angular $resource and errorResult JSON handling

I have a Spring Rest service exposed and from Angular controller, using Angular Resource service I communicate with it. In my service I have implemented exception handling and with standard error response I return an Json object that contains data like errorCode, erorrMessage and errorDescription.

Now i want to handle that Json in errorResult just like in the successResult in order to show the errorDescrption on the web page. How can I do this?

This is the example of the resource service usage:

var configGet = config.get({}, function(successResult) {
$log.debug("Service responded successfully");
$log.debug(successResult);
$scope.data = successResult.content;
$scope.totalItems = successResult.totalElements;
}, function(errorResult) {
$log.error("Service responded with ERROR");
//How to get errorDescrption from erorrResult?
});

Answer

OK, I got the solution and its very simple, I dont know how I didnt see it...

To get errorDescrption is simple as this:

var errorDescrption  = errorResult.data.errorDescrption