My http backend call may have exceptions, if it fails, my method doesn't continue with the rest of the instructions (//do something else). How to continue the execution even if there are exceptions?
public updateStatus(status: string): void {
this.userApiService.user.updateStatus(status, this.user.objectKey).subscribe((response) => {
//do something else
);
}
CodePudding user response:
Add the catchError
operator.
import { catchError } from 'rxjs/operators';
public updateStatus(status: string): void {
this.userApiService.user.updateStatus(status,this.user.objectKey
.pipe(
catchError(e => /* handle error and return a handable error response */),
).subscribe((response) => {
//do something else
);
}
CodePudding user response:
import { finalize } from 'rxjs/operators';
public updateStatus(status: string): void
{
this.userApiService.user.updateStatus(status,this.user.objectKey)
.pipe(finalize(() =>
{
//do something even after exception
}),
.subscribe((response) =>
{
}, error => console.error(error));
}