Reputation: 225
this.service.login().pipe(
catchError((error: HttpErrorResponse, responseObservable: Observable<boolean>) => {
if (error.status === 400) {
return this.service.doSomethingElse.pipe(map(() => throwError(error)));
} else {
return throwError(error);
}
}),
).subscribe(
The response from this is always a 200, It won't throw the error when the status code is 400 and return from making the other request. Any help would be great.
Upvotes: 2
Views: 609
Reputation: 11000
With map()
you map values from this.service.doSomethingElse
Observable to throwError(error)
Observable, so you get stream of streams.
You should flatten it with mergeMap
or other flattening operator. Like:
return this.service.doSomethingElse.pipe(mergeMap(() => throwError(error)));
Upvotes: 4
Reputation: 22213
Try this:
this.service.login()
.subscribe((res: any) => {
}, error => {
if (error.status === 400) {
return this.service.doSomethingElse.pipe(map(() => throwError(error)));
} else {
return throwError(error);
}
})
Upvotes: 0