Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

$q.reject() returns a promise with then() but no catch() and no finally() #6048

Closed
wesleyakio opened this issue Jan 29, 2014 · 5 comments
Closed

Comments

@wesleyakio
Copy link

When creating a rejected promise with $q.reject(reason) the resulting promise does not have the catch and finally methods.

@wesleyakio
Copy link
Author

Currently overriding $q.reject in a decorator, a little bit annoying since the decorator must go into every single module that depends on catch and finally from the reject sugar...

$provide.decorator('$q', function($delegate) {
  $delegate.reject = function(reason){
    var deferred = $delegate.defer();
    deferred.reject(reason);
    return deferred.promise;
  };
  return $delegate;
});

The "light" promise returned from $q.reject should perform better, but returning a "real" rejected promise might make things easier when extending the promise itself.

@lgalfaso
Copy link
Contributor

#5976 should be able to handle this

@wesleyakio
Copy link
Author

Looking at the pull request it does seem to handle it.

Will the path to compliance eventually lead angular to drop support for catch and finally?

@ghost ghost assigned tbosch and IgorMinar Jan 31, 2014
@IgorMinar
Copy link
Contributor

we should fix this in 1.2 (#5976 can't go into 1.2)

lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Jan 31, 2014
Add support for the functions `finally` and `catch` to the
promise returned by `$q.reject`

Closes angular#6048
@lgalfaso
Copy link
Contributor

@IgorMinar you are right, will create a new PR just for this fix

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants