You can also cancel/end a pipe by using a signal Subject
and the rxjs operator: takeUntil
Example
httpGetSafe(path: string): Observable<Data> {
const stopSignal$ = new Subject();
return this.http.get<Data>(path).pipe(
map(data => {
const isBad = data === null;
if (isBad) {
stopSignal$.next();
}
return data;
}),
takeUntil(stopSignal$)
);
}
Sometimes it’s a bit simpler and more flexible than throwing errors…