-
Notifications
You must be signed in to change notification settings - Fork 27.6k
Is re-throwing in promises going to be supported by $q at some point? #13990
Comments
Throwing an error from within a It seems like you have misinterpreted the quoted statements:
This only refers to the throwing from within the contructor (i.e. $q(function (resolve, reject) {
throw new Error('From constructor !');
}).then(
// Will never get here unless you call `resolve()` or `reject()`.
// Throwing won't work !
); But it's OK, because when using
The key word here is "forward". Throwing an error will still work for rejecting the promise, but it does not do a good job at forwarding the initial error, because the next rejection handler will get your thrown error as argument. Closing as it seems like what you are asking is already supported. |
@gkalpak thanks for the reply, I guess I misinterpreted the first paragraph indeed. But, what I am interested in, is indeed the ability to rethrow anything, be it null, a string, or a custom object, and not necessarily an exception/error object. This works for example in Ember's promise library, and can be quite handy. doSomething
.then(() => {
throw 'foo';
})
.catch(reason => {
console.log(reason); //foo
}); Can I take from your reply that this use case is not supported and will not be supported by |
@adambuczynski, ooops, how did I miss that ? Obviously you can throw anything and it works as you expect it to. (I guess I'm too used to throwing only The only difference between is that Sorry for the confusion 😞 |
@gkalpak No worries, and thanks for the clarification. Now that you've mentioned that, I remember why I wasn't using Is there a way to turn off that behaviour in |
Unfortunately, you can only decorate |
Yeah I was thinking of decorating |
There's no easy way to skip the call to |
Alright, I'll stick to using |
Angular 2 prefers Observables (not promises), but you can still use promises. Since ng2 uses zones, you can use native implementations and hooking in your library of choice should be fairly easy (although I haven't tried that). But you'll probably want to use observables and not miss out on the new features the bring on the table 😁 |
Will give them a shot for sure, thank you. |
The docs for
$q
state:and
So my question is, is this planned to be supported at any time in Angular 1? In a successful
.then
chain we can keep returning the same item/data, or modify it and return that, so why not re-throw an error in.catch
that occurred without needing to include$q
as a dependency?E.g.
instead of:
If not, is there a specific reason for this not being supported in
$q
?The text was updated successfully, but these errors were encountered: