Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle factory service errors in AngularJS
    primarykey
    data
    text
    <p><strong>Factory code</strong></p> <pre><code>app.factory('abcFactory', function ($http, Config, $log) { var serviceURL = Config.baseURL + '/results'; return{ results:function() { var promise = $http({ method: 'GET', url: serviceURL, timeout: Config.httpTimeout }).then(function(response) { return response; }, function(reason) { $log.error("Request Failed: ", reason) }); return promise; } } }); </code></pre> <p><strong>Controller code</strong></p> <pre><code>app.controller('abcController',function ($scope, $log,abcFactory, Config) { abcFactory.results(function(data){ $scope.results =data; },function(response) { console.log("response"+response); if(response.status === 0) { console.log("gotcha"); $scope.serviceTimedoutError(response.data, response.status, response.config); } else { console.log("gotcha"); $scope.serviceFailure(response.data, response.status, response.config); } }); }); </code></pre> <p><code>$scope.results</code> populates fine when service has returned good response.</p> <p>And, when there is an error I can see on console the error message coming from factory code's log saying <code>"Request Failed: blah blah "</code>.</p> <p><strong>My issue:</strong> When there is an error, why I am not seeing error message in controller, it is not even printing <code>"gotcha"</code> in browser console. I need error details in controller, so that I can show it on view. I don't want to pass <code>$scope</code> in factory.</p> <p>What wrong I am doing in Controller code?</p> <p>If I am not wrong, I am doing something in line of <a href="https://stackoverflow.com/questions/11598097/angularjs-failed-resource-get">AngularJS Failed Resource GET</a> but not getting desired result.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload