Im trying to handle some custom errors on a Observable.
I want to exit a subscription if I throw a new custom error. But no matter what I try it still proceeds the process without any errors thrown.
Im trying to exit the subscribe function and skip to the error handler, but my following code is not working as expected..
const obs = new Observable((observer) => {
observer.next();
}).pipe(
map(() => {
return "Some Data";
}),
tap(() => {
if (true) { // Some condition
return throwError( new Error("Test error") )
}
}),
catchError(() => {
return throwError( new Error("Test error") );
})
)
obs.subscribe((res) => {
console.log("[OBS]", res); // Actual triggered handler
}, err => {
console.log("[OBS]", err); // This handler should be actually triggered
})