Catches errors on the observable to be handled by returning a new observable or throwing an error.
Example in action:
public updateExperience(formValue: EmployeeExperiences): void {
this.loader = true;
this.employeeExperienceService.update(formValue, 'Experience')
.pipe(
catchError(err => {
this.loader = false;
this.isError = true;
this.outputMessage = `Error:${err.status}. It seems something went wrong, please try later`;
return throwError(err);
}),
takeUntil(this.onDestroy$)
)
.subscribe(res => {
this.isSaved = true;
this.outputMessage = `Great job! Your information has been updated correctly,
please close this window if you do not need to run more updates on it`;
// Update current item in array
const itemToFind = this.experienceList.find(x => x.id === res.id);
for (let index = 0; index < this.experienceList.length; index++) {
if (this.experienceList[index].id === itemToFind.id) {
this.experienceList[index] = res;
}
}
});
}