Skip to main content

rejectedObservablePipe

Alternative: rejected$$$

Inlined: rejectedObservable, rejected$$

Types

function rejectedObservablePipe<GInNextValue, GOut>(
onRejected: IThenObservableOnRejected<GOut>,
): IObservablePipe<IThenObservableInNotifications<GInNextValue>, IRejectedObservableOutNotifications<GInNextValue, GOut>>
export type IRejectedObservableFulfilledNotifications<GInNextValue> =
| INextNotification<GInNextValue>
| ICompleteNotification;

export type IRejectedObservableOutNotifications<GInNextValue, GOut> =
GOut
| IRejectedObservableFulfilledNotifications<GInNextValue>;

Definition

This function is similar to the method .catch of a Promise.

It returns:

thenObservablePipe<GInNextValue, IRejectedObservableOutNotifications<GInNextValue, GOut>>(
singleWithNotifications,
onRejected,
);

Example

Catch a failed http request

const subscribe = pipe$$(throwError(new Error(`Rejected`)), [
rejected$$$((error: any): IObservable<IDefaultNotificationsUnion<string>> => {
if (navigator.onLine) {
return throwError(error);
} else {
return singleWithNotifications('Offline');
}
}),
]);

subscribe((notification) => {
console.log(notification.name, notification.value);
});

Output (if browser is online):

'error', Error(`Rejected`)

Output (if browser is offline):

'next', 'Offline'
'complete', undefined