currently I have my code structured like this, and it is working great:
// service:
getRequestA() { return this.http.get(someUrl) }
getRequestB(id) { return this.http.get(someUrl + id) }
getRequestC(id) { return this.http.get(someUrl + id) }
getAll() {
return getRequestA()
.pipe(
mergeMap((resp) => {
return this.getRequestB(resp.id)
}),
mergeMap((resp) => {
return this.getRequestC(resp.id)
})
)
}
which allows me to do this in my component:
// component:
service.getAll().subscribe(resp => {
// result of service.getRequestC()
}, error => {
// error occurred in any 1 of the 3 http calls
});
This is great as I need the result of each call before firing off the next, and I only care about the final result. However, now I have a desire to know which specifically of the 3 http calls failed, to display a better error to the user. I've tried a bunch of stuff but can't figure out to throw custom errors in the service that I could then differentiate between in the component. Thanks in advance for any suggestions!