The following service are invoked in the controller:
//Controller
$scope.groups = CrudService.getAllGroups();
This service returns all groups from the database. So next, as shown below, the service code:
//Service (CrudService)
function getAllGroups() {
return ResService.group.query(
successResponse,
errorResponse);
}
function successResponse(resp) {
return resp;
}
/*This part doesn't work*/
function errorResponse(error) {
return function (err) {
$scope.msgError = false;
$scope.errStatus = err.status;
$scope.statusText = err.statusText;
$scope.errMsgDetail = err.data.MessageDetail;
};
}
/**************************/
//Nested Service (ResService)
return {
group: $resource(baseUrl + '/api/group/:Id', {
Id: '@Id'
}, {}),
}
How you can see in the service code, the error response won't invoked in the view. I'm using the error messages from the response header respectively the backend. If the request failed then the alert box have to displayed as the following code demonstrates:
<div>
<alert ng-hide="msgError" type="alert alert-danger" close="closeAlert()">
<p><b>{{ statusTitle }}</b>: <i>{{ errStatus }} - {{ statusText }}</i></p>
<p><strong>{{ msgTitle }}</strong>: <i>{{ errMsgDetail }}</i> <i>{{ msgException }}</i></p>
</alert>
</div>
Do anyone has an idea how I can access or correctly define the values in the errorResponse function? Or, is it possible to declare in the service query at all?