BACK
ReferencethrowIfEmpty
Reference · 110

throwIfEmpty

throwIfEmpty

rxjs.dev

Turns an empty complete into an error.

Signature

throwIfEmpty(errorFactory?: () => any): MonoTypeOperatorFunction

What it does

If source completes without any next, it creates an error and sends it down the error channel. If there were values, it passes them through as usual.

When to use

When an empty result violates a contract: a required user, a required configuration, an expected entity.

See also

defaultIfEmpty, isEmpty, catchError

script.ts // TypeScript
CONSOLE · Console output
Hit Run to see the result...