Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / src/public-api / throwError

Function: throwError() ​

throwError<T>(message): Operator<T, never>

Defined in: projects/libraries/streamix/src/lib/operators/throwError.ts:19

Creates a stream operator that throws an error with the provided message as soon as the source produces a value.

When a consumer requests a value by calling next(), the operator pulls the source: if a value arrives, it throws an Error with the given message instead of emitting; if the source completes without emitting, the operator completes normally without erroring.

This is useful for testing error handling logic in a stream pipeline or for explicitly modeling a failed asynchronous operation.

Type Parameters ​

T ​

T = any

The type of the values in the source stream (this is a formality, as no values are emitted).

Parameters ​

message ​

string

The error message to be thrown.

Returns ​

Operator<T, never>

An Operator instance that errors when the source emits.

Released under the MIT License.