Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS possible unhandled rejection when using ui-router

After I have changed from ngRoute to angular-ui-router the console shows always 4 errors stating: Possibly unhandled rejection: {}

I did not noticed any "problem" in the behavior of the application I am building, but I would like to get rid of it.

Any idea what does it mean and how to solve it?

Here an screenshot: enter image description here

like image 905
Rafael Munoz Avatar asked Oct 08 '16 11:10

Rafael Munoz


3 Answers

I used the next solution

    $http.get('/api/get').then(function(result) {
       // ... stuff here
    }).catch(angular.noop);

it's equals to

$http.get('/api/get').then(function(result) {
  // ... stuff here
}).catch(function(){});
like image 123
Andrey Ravkov Avatar answered Nov 11 '22 09:11

Andrey Ravkov


This issue is found in 1.5.9 and 1.6.0-rc-0. More details at https://github.com/angular-ui/ui-router/issues/2889

Patch solution is to manually disable unhandled rejections.

app.config(['$qProvider', function ($qProvider) {
    $qProvider.errorOnUnhandledRejections(false);
}]);
like image 22
Artem K. Avatar answered Nov 11 '22 08:11

Artem K.


If you look at the logic for uiCanExit in angular-ui-router file(I'm using v1.0.16), it checks only for resolved promise but not for a rejected promise. It is something like:

promise.then(function (val) { 
    return val !== false ? next_transition : current_transition
});

Just return a resolved promise with false value to cancel transition. e.g.,

defer.resolve(false)
like image 1
anudeep b Avatar answered Nov 11 '22 10:11

anudeep b