I am trying to use concatMap
to allow me to run requests in a sequential order without having to visually subscribe to every request that I am sending.
Everything is working fine, however when there is an error it carries on running through the pipe, which I do not want.
If it fails, I just want to be able to cancel all of the requests, stop it from running and display something. I have tried catchError
however this doesn't seem to work / do what I want.
Take this example...
I want to reset a users password, upon password reset I want to POST
to the /password/resets
endpoint, I then want to automatically log the user in, so for that I then want to post to /auth/login
and I then want to get the user GET - /user
so I can use it throughout the application. If the request fails at any stage. I want to stop the pipes and throw a generic error which is shown at the bottom of the question.
this.userService.resetPassword(password)
.pipe(concatMap(() => this.authService.login(user.email, password)))
.pipe(concatMap(() => this.userService.me()))
.subscribe((user: User) => {
this.userService.setUser(user);
});
Example:
this.userService.resetPassword(password)
.pipe(concatMap(() => this.authService.login(user.email, password)))
<-- IF IT FAILS ON THE ABOVE / ANY REQUEST I WANT TO STOP ALL REQUESTS AND SHOW NOTIFICATION -->
.pipe(concatMap(() => this.userService.me()))
.subscribe((user: User) => {
this.userService.setUser(user);
});
The below snippet is something that I want to run on an error -
this.notificationService.notify('Unable to reset password, please try again.');