У меня есть следующий код, который я пытаюсь реорганизовать только с одной подпиской без успеха.
this.emailsService.askOptionOne(email).pipe(
takeUntil(this.ngUnsubscribe)
).subscribe(
() => {
this.isBusy = false;
assistanceForm.reset();
this.router.navigate(['/']);
this.translateService.get('The request has been sent.').subscribe((message: string) => {
this.toastrService.success(message);
});
},
(error: any) => {
this.isBusy = false;
this.translateService.get(error).subscribe((message: string) => {
this.toastrService.error(message);
});
}
);
Что я пытаюсь сделать до сих пор:
this.emailsService.askOptionOne(email).pipe(
switchMap(() => of('The request has been sent.')),
catchError((error: any) => of(error)),
switchMap((message: any) => this.translateService.get(message)),
takeUntil(this.ngUnsubscribe)
).subscribe(
(message: any) => {
this.isBusy = false;
assistanceForm.reset();
this.router.navigate(['/']);
this.toastrService.success(message);
},
(error: any) => {
this.isBusy = false;
this.toastrService.error(error)
}
);
Проблема с этой версией заключается в том, что в результате никогда не возникает ошибка.
Любой ключ к рефакторингу этого кода?
Спасибо за вашу помощь.