Take a look at the structure of my angular application outlined below:
Within my 'firm.html' page, there is a button that triggers the code snippet provided.
Controller
The controller initiates a Service function. The use of generationInProgress
in an ng-show function toggles the visibility of a loading icon on the HTML page.
$scope.generationInProgress = true;
firmService.processFirm(firmRequest).then(function(response) {
window.location.href = "firm/process";
$scope.generationInProgress = false;
});
Firm Service
This service manages Firm operations with the mentioned function.
this.processFirm = function(firmRequest) {
return httpService.put('firm/process', firmRequest);
};
HTTP Service
This service handles all service calls for multiple services, including firmService. Below is the put
method being referenced.
this.put = function(url, data) {
return promise = $http.post(url, data).success(function(response) {
return response;
}).error(function(response) {
console.log("error");
});
};
In case of a HTTP error code from the server, the .error
function is executed. If there was a dedicated error page, a redirect could be initiated to that page.
However, the challenge lies in displaying the error on the 'firm.html' page while also resetting $scope.generationInProgress
to hide the loading icon. This task cannot be handled within httpService due to its generic usage across various components.
I am uncertain about how to transmit the error back to the controller to achieve this goal. Would inserting return response;
in both .success
and .error
functions and then utilizing an IF statement in the controller suffice to check for the HTTP code? Are there other methods worth exploring?
Any insights or suggestions would be greatly valued.