3

Please click here to see my issue

I got the error:

Possibly unhandled rejection: {}

I read the solution in this topic : Angular 1.6.0: "Possibly unhandled rejection" error

i tried But i dont know where i put fixed code, please kindly help me, thanks Thanks all !

georgeawg
  • 48,608
  • 13
  • 72
  • 95
J.Tran
  • 115
  • 1
  • 8
  • 1
    You can put it anywhere in a .config block (i.e. where you define your routes). That looks like a bandaid for a real issue, you'd be much better off figuring out the actual issue and fixing it. – BShaps Aug 13 '18 at 23:15
  • 1
    Surely this is not a real solution, since angular 1.5.9 people are getting this issue because of unhandled rejection. I recommend you to first check your angular-ui-router version, check if you are using the most recently (1.0.20). If you're already using it, check if you have any promises that you don't have the error handler function or the catch case you have a promise. Hope this solves your problem. Don't hide your problem with the `$qProvider`. – Luiz Carlos Aug 14 '18 at 00:34

1 Answers1

3

First option is simply to hide an error by disabling them with errorOnUnhandledRejections in $qProvider configuration:

app.config(['$qProvider', function ($qProvider) {
    $qProvider.errorOnUnhandledRejections(false);
}]);

BUT this will only switch off logging. The error itself will remain

The better solution in this case will be - handling a rejection with .catch() method:

service.doSomething()
 .then(function (response) {
   //normal processing
})
 .catch(function (err) {
     console.log(err);
     throw err;
});

Useful Links:

georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • 2
    It's not really a better solution when maintaining a tens of thousands of lines app that you've just spend half a year upgrading to v1.7. Going back and added noop code to every single $timeout you used to work around the inadequacies of $scope.$apply is actually just a complete waste of time, all because somebody decided that last release of a framework they're killing is the right time to tell people how to do promises (which they replaced in Angular2 anyway). – toxaq Sep 19 '19 at 06:05
  • What if I don't know which promise is failing? What, exactly, is a promise? I don't make any implicit promises in my code (don't use $http), services, etc. I ***do*** use ui-router, so maybe that adds a promise? Or just having a controller? I don't know what those do under the hood, so have [an open question](https://stackoverflow.com/questions/60350813/angularjs-1-7-9-how-to-debug-possibly-unhandled-rejection/60388277) with bounty to ask for a generic way of debugging this question. – Mawg says reinstate Monica Feb 26 '20 at 07:02