I am facing an issue with managing multiple http calls and handling errors that may occur during their execution. I want to be able to identify which calls have failed so that I can retry them using a different method. However, without visibility at the component level, it becomes challenging for me to determine which specific call needs to be retried.
// COMPONENT CALL
generateDocuments(documentType: DocumentType, validDocuments: DocumentTemplate): observable<any>{
return this.documentService.generateDocuments(clientId, ClientDescription, documentType, validDocuments)}
//SERVICE CALL:
generateDocuments(clientId: int, ClientDescription, documentType:DocumentType, validDocuments: DocumentTemplate): observable<any>{
switch(documentType){
documentType.Word:{
return this.getDocumentCall(clientId, ClientDescription, ...)}
documentType.Excel:{
return this.getDocumentCall(clientId, ClientDescription, ...)}
}
// This line will throw an error/success one by one depending on when the call complete
private getDocumentCall(clientId: int, clientDescription: string, ....)
{
return forkjoin([1,2,4,4,5].map((documentId:number) => {
this.http.get('uri'+documentId+'/'+clientId,headers..).pipe( catchError(error => {
return of(error);
});
});
I am looking for a way to track successful or failed calls at the component level, or find a method to bubble up all errors/responses to the component level for better management.
Thank you