3

I constantly have this error Possibly unhandled rejection even when using $promise.then(success, err) or $promise.then(success).catch(err)

What should I do to fix this error. Thanks


this is the code

this.User = $injector.get('User');
this.User.get(id).$promise
.then(fn, fn)

in the User resource:

class UserResource {
    constructor($resource) {
        'ngInject';
        this.$resource = $resource;
    }
    get(id) {
        return this.$resource(apis.user + id).get();
    }
}
georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • 1
    You mean it's a warning not an error, right? – Aluan Haddad Jan 05 '20 at 15:43
  • @AluanHaddad It's an error ```console.error```, and it's caught on Sentry as a javascript error. – Andrew Lawendy Jan 05 '20 at 15:50
  • 2
    @Andrew Hani [Possibly unhandled rejection](https://stackoverflow.com/a/44009080/9744379) this may help – Vignesh A Jan 05 '20 at 16:45
  • 3
    Does this answer your question? [Possibly unhandled rejection: {}](https://stackoverflow.com/questions/51831457/possibly-unhandled-rejection) – Vignesh A Jan 05 '20 at 16:47
  • 1
    A better solution might be to swap out angular promises for Native promises given what the linked answer said. Thanks @VigneshA – Aluan Haddad Jan 05 '20 at 18:37
  • 1
    @AluanHaddad Native ES6 promises are not integrated with the AngularJS framework. Only operations which are applied in the AngularJS execution context will benefit from AngularJS data-binding, exception handling, property watching, etc.. – georgeawg Jan 05 '20 at 19:17
  • yeah, but it's easy to Monkey patch them in – Aluan Haddad Jan 05 '20 at 22:20
  • 1
    @VigneshA The issue with these solutions that it tackles a 1.6 version and mine is 1.7.9, and it suggests to simply hide the error ```$qProvider.errorOnUnhandledRejections(false);``` which is not ideal. @AluanHaddad can you explain what do you mean by Monkey Patch in this case? Thanks a lot. – Andrew Lawendy Jan 06 '20 at 08:53
  • @georgeawg I did as you suggested in the links but the error still persists! – Andrew Lawendy Jan 06 '20 at 09:12
  • 1
    To re-open the question, I need code that reproduces the problem. See [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – georgeawg Jan 06 '20 at 19:56
  • @georgeawg this is the code ```this.User = $injector.get('User'); this.User.get(id).$promise .then(fn, fn)``` in the User resource: ```class UserResource { constructor($resource) { 'ngInject'; this.$resource = $resource; } get(id) { return this.$resource(apis.user + id).get(); } }``` – Andrew Lawendy Jan 08 '20 at 15:43

0 Answers0