I use the same error handling for multiple rxjs functions:
f1() {
this.error = undefinded; //*
obs1$.subscribe({
next: () => some_code,
error: error => this.error = error //*
})
}
f2() {
this.error = undefinded; //*
obs2$.subscribe({
next: () => some_other_code,
error: error => this.error = error //*
})
}
how do I factor out the code marked with //*
2
Answers
Here’s one way using a custom operator that wraps the rxjs
catchError
operatorUse it like this
Refer sample below :