mardi 5 avril 2016

How to handle server down requests (AngularJS)

I'm making a POST request to a TOMCAT server using AngularJS. Below is a snippet of that code.

$http(<myRequest>).then(function(response) {
            $scope.info = response.data;
        }, function(response) {
            $scope.error = response.data
        });

This works fine as long as the server is up and running. In case of any error on the response, it populates the $scope.error variable with the error message. However, if the server is down, when I click the link that makes this request nothing is shown on the page, I can only see the error on the console of the browser.

How do I show this error on the page? I want to somehow notify the user that the server is down.




Aucun commentaire:

Enregistrer un commentaire