Rxjs Fallback Value on Error by Example

Image by Ernesto Rodriguez from Pixabay

Handlers

const streamHandler = value => {
console.log(`Hello ${value}`);
};const errorHandler = value => {
console.log(`${value} oh oh!`);
};const completionHandler = () => {
console.log(`All done!`);
};

Error

const error = throwError("Error!").pipe(
catchError(err => of("Error Replacement "))
);

Example

error.
pipe(
error.subscribe(streamHandler, errorHandler, completionHandler);
//Hello Error Replacement

Summary