RxJS is a library for reactive programming using Observables, to make it easier to compose asynchronous or callback-based code.
How to fix catchError()
function issue.
How to reproduce it
.pipe(
tap(() => {
this.notification.addSuccess('Location detected');
}),
catchError((err: any) => {
this.notification.addError(err.message)
})
)
Error
error TS2345: Argument of type '(err: any) => void' is not assignable to parameter of type '(err: any, caught: Observable<T>)
Solution #1
Add throw statement.
.pipe(
tap(() => {
this.notification.addSuccess('Location detected');
}),
catchError((err: any) => {
this.notification.addError(err.message)
throw 'Error: ' + err.message;
})
)
Solution #2
Return a new observable.
.pipe(
tap(() => {
this.notification.addSuccess('Location detected');
}),
catchError((err: any): Observable<any> => {
this.notification.addError(err.message)
return new Observable(observer => observer.next(defaultData));
})
)