Suppose I have the following
function getData() {
return this.http.get('data');
}
...
getData().subscribe({
complete: () => {
this.closeDialog();
});
}
Not tested, but I think this should work. However, the this.http call can throw an error. That can be fixed as follows
getData().subscribe({
error: (err) => { this.showNotification(err) },
complete: () => { this.closeDialog() }
});
or I could catch it inside getData
function getData() {
return this.http.get('data').pipe(catchError(err => {
return of({});
});
}
What I would like to do is:
- If the
subscribedefines anerrorhandler, don't catch the error insidegetData - If the subscribe doesn't define an
errorhandler, catch the error insidegetData
Is this possible? If not, I'm all ears to other suggestions/solutions!