UPDATE :
I'm currently facing a challenging issue that I can't seem to resolve. Within my code, there is a list of objects where I need to execute 3 requests sequentially for each object, but these requests can run in parallel for different objects.
To handle this, I've implemented a forkjoin
operation to execute the code once all queries are completed. However, the loop executes all procedures even if errors occur.
I made some modifications to my code so that the 3 procedures now run one after the other successfully. However, in case of an error, the catchError block isn't executed as expected. The code continues to connect procedure 1, 2, and 3 even if procedure 1 encounters an error.
It's crucial that procedure 3 (this.store.proc3) is still executed even after encountering an error.
this.list.forEach(obj => {
var input1 = obj...;
var input2 = obj...;
var input3 = obj...;
var obs = this.store.input1(input1).pipe(
catchError(err1 => this.store.proc3(input3, "ERR")),
concatMap(res1 => this.store.proc2(input2).pipe(
catchError(err2 => this.store.proc3(input3, "ERR"),
concatMap(res2 => this.store.proc3(input3, "OK")
))
);
_obs$.push(obs);
}
forkJoin(_obs$).subscribe(
results => {
if(results) {
this._dialogRef.close(true);
// ...
}
}
);
CURRENT CASE :
- proc1 OK -> proc2 OK -> proc3(OK)
- proc1 OK -> proc2 ERR -> proc3(OK)
- proc1 ERR -> proc2 ERR -> proc3(OK)
DESIRED CASE :
- proc1 OK -> proc2 OK -> proc3(OK)
- proc1 OK -> proc2 ERR -> proc3(ERR)
- proc1 ERR -> proc3(ERR)
INFOS :
- proc1 -> return true OR exception
- proc2 -> return true OR exception
- proc3 -> return object (allows you to change the status of the object)
If anyone has a solution, I would greatly appreciate it as I am unfamiliar with RxJs.