-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: allow throwError
to accept a factory function
#5617
Labels
feature
PRs and issues for features
Comments
benlesh
added
AGENDA ITEM
Flagged for discussion at core team meetings
type: discussion
labels
Jul 31, 2020
General approval from core team. |
benlesh
added
feature
PRs and issues for features
and removed
AGENDA ITEM
Flagged for discussion at core team meetings
type: discussion
labels
Aug 12, 2020
benlesh
added a commit
to benlesh/rxjs
that referenced
this issue
Aug 16, 2020
- Adds feature to allow the error instance the consumer is notified with to be created at the moment of notification. - Updates tests to use "run mode". - Improves documentation, including recommendations on when `throwError` is not necessary. BREAKING CHANGE: In an extreme corner case for usage, `throwError` is no longer able to emit a function as an error directly. If you need to push a function as an error, you will have to use the factory function to return the function like so: `throwError(() => functionToEmit)`, in other words `throwError(() => () => console.log('called later'))`. resolves ReactiveX#5617
benlesh
added a commit
that referenced
this issue
Aug 18, 2020
* feat(throwError): now accepts a factory to create the error - Adds feature to allow the error instance the consumer is notified with to be created at the moment of notification. - Updates tests to use "run mode". - Improves documentation, including recommendations on when `throwError` is not necessary. BREAKING CHANGE: In an extreme corner case for usage, `throwError` is no longer able to emit a function as an error directly. If you need to push a function as an error, you will have to use the factory function to return the function like so: `throwError(() => functionToEmit)`, in other words `throwError(() => () => console.log('called later'))`. resolves #5617 * chore: clean up and address comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The thought is this: Frequently, you don't want to create an
Error
object until the moment the error happens. However, currently,throwError
only accepts the instance of the error it is going to throw as an argument.I'm wondering if we could allow it to optionally take a factory function that will create the error at the moment of subscription.
This would be a breaking change, however, as right now, it's possible to emit a function as an error by using
throwError
:Current behavior when you provide a function
Proposed change
The text was updated successfully, but these errors were encountered: