I am faced with a challenge of executing an array of HTTP requests in a specific order, where if any request fails, the subsequent ones should not be executed.
Is there a way to achieve this requirement?
What would be the recommended approach to handle this scenario?
In order to address this issue, I have developed the following solution:
let failed: boolean = false;
payloadArray.forEach(payload => {
if (!failed) {
http.post(this.url, payload, this.options)
.map((res: Response) => {
return res.json;
})
.catch((error: any) => {
failed = true;
Observable.throw(error.json().error || 'Server error')
});
}
}