I have a function that sends requests to the server as long as the field hasProcessado (hasProcessed in English) is false. Once it turns true, the function should stop sending new requests. A maximum of 10 requests are allowed, but if there's an error, it will only try 3 times.
However, on the server side, even when hasProcessado == true
, it continues to send requests. Strangely, local testing shows that it works correctly.
public pullingPerfilInvestor(): Observable<any> {
let result = this.http.get<PerfilInvestor>(this.configService.generateNewUrl(`${environment.api.endpoints.obterPerfil}`), { headers: this.configService.concatenateHeaders(true) })
return result
.pipe(
concatMap(res => iif(() => res.hasProcessado,
of(res),
interval(500).pipe(
take(9),
concatMap(() => result)
)
)),
catchError(err => {
return throwError(err);
}),
retryWhen(errors =>
errors.pipe(
delayWhen(val => timer(500)),
concatMap((error, index) => {
if (index === 2) {
return throwError(error)
}
return of(null);
}),
take(3)
)
),
shareReplay(1),
last()
);
}
Data Object in SoapUi:
{
"perfil": {
"hasPerfil": true,
"descricao": "Arrojado",
"aderencia": {
"exibirMensagem": true}
},
"questionario": {
"vencimento": "01.12.2021",
"isVencido": false
},
"hasProcessado": false
}
In my local browser, it makes 10 requests because in SoapUi hasProcessado == false:
https://i.sstatic.net/74V8M.png
While hasProcessed is false:
https://i.sstatic.net/KXrwB.png
Once hasProcessado changes to true, it continues to make requests.
https://i.sstatic.net/15Gv2.png
Data Object in the server:
{
"hasProcessado":true,
"dataPosicao":null,
"perfil":{
"hasPerfil":true,
"descricao":"Arrojado",
"aderencia":{
"isExibirMensagem":false
}
},
"questionario":{
"vencimento":"15.06.2022",
"isVencido":false
}
}
NB: I suspect there might be an issue with the concatMap and iff logic within the code.