I am using angular material stepper, and after each step I send data to backend. So, I have this method in me fist step, that return LeadStatusRequest the following kind:
export interface LeadStatusRequest {
id: number;
value: string;
publicId: string;
}
and put method:
public submit(): Observable<LeadStatusRequest> {
return this.dataService
.putData(this.formData)
.pipe(
catchError(err => {
const emailErrorText: string =
'Email address already exists. No update performed';
if (err.error.Errors.find(error => error.includes(emailErrorText))) {
this.formGroup.controls.emailAddress.setErrors({notUniqueEmail: true});
return throwError({isSkippedNotification: true});
}
return throwError(err);
}),
);
}
So I should check if the result of submit method returns object with key "publicId", I should set it to localstorage. I try do this, but in this case I have a several put requests
public submit(): Observable<LeadStatusRequest> {
this.dataService.putData(this.formData)
.subscribe(res => {
if (res.publicId) {
this.authService.setPublicId(res.publicId);
}
});
return this.dataService
.putData(this.formData)
.pipe(
catchError(err => {
const emailErrorText: string =
'Email address already exists. No update performed';
if (err.error.Errors.find(error => error.includes(emailErrorText))) {
this.formGroup.controls.emailAddress.setErrors({notUniqueEmail: true});
return throwError({isSkippedNotification: true});
}
return throwError(err);
}),
)
}
It looks like you want to:
this.dataService.putDatacallYour
catchErroroperator will only run if there is an error. All you need to do is handle the success response in an operator beforecatchError. You can perform actions using thetapoperator.