A factory function that will create the error instance that is pushed.
Returns an observable that will error with the specified error immediately upon subscription.
The error instance to emit
Support for passing an error value will be removed in v8. Instead, pass a factory function to throwError(() => new Error('test'))
. This is
because it will create the error at the moment it should be created and capture a more appropriate stack trace. If
for some reason you need to create the error ahead of time, you can still do that: const err = new Error('test'); throwError(() => err);
.
Notifies the consumer of an error using a given scheduler by scheduling it at delay 0
upon subscription.
An error instance or error factory
A scheduler to use to schedule the error notification
The scheduler
parameter will be removed in v8.
Use throwError
in combination with observeOn: throwError(() => new Error('test')).pipe(observeOn(scheduler));
.
Details: https://rxjs.dev/deprecations/scheduler-argument
Generated using TypeDoc
Creates an observable that will create an error instance and push it to the consumer as an error immediately upon subscription.
Just errors and does nothing else
This creation function is useful for creating an observable that will create an error and error every time it is subscribed to. Generally, inside of most operators when you might want to return an errored observable, this is unnecessary. In most cases, such as in the inner return of concatMap, mergeMap, defer, and many others, you can simply throw the error, and RxJS will pick that up and notify the consumer of the error.
Example
Create a simple observable that will create a new error with a timestamp and log it and the message every time you subscribe to it
Unnecessary usage
Using
throwError
inside of an operator or creation function with a callback, is usually not necessaryYou can just throw the error instead