Hi Team,
I have parallel call as showed below, at present if other API is failed for one AccountID, then complete call considering as fail. Could you please let me know how I can make the call better, Even if one AccountID is failed still I need to continue with final response for the success AccountID.
- public async Task<List<CreditCardSummary>> Process(Dictionary<string, string> permanentIds)
- {
- List<Task> tasks = new List<Task>();
- List<CreditCardSummary> creditCardSummaryServiceList = new List<CreditCardSummary>();
- foreach (var permanentId in permanentIds)
- {
- CreditCardSummaryRequest request = new CreditCardSummaryRequest()
- {
- AccountID = permanentId.Key,
- AccountToken = permanentId.Value
- };
- tasks.Add(ModelServiceProcessing(request).ContinueWith(
- (TResult) => creditCardSummaryServiceList.Add(TResult.Result)));
- }
- await Task.WhenAll(tasks.ToArray());
- return creditCardSummaryServiceList;
- }
- public async Task<CreditCardSummary> ModelServiceProcessing(CreditCardSummaryRequest request)
- {
-
- var restServiceResponse = await restClient.Post(ccStatusInfoUrl,request ,true, header);
- var restServiceResponseInformation = await restServiceResponse.Content.ReadAsStringAsync();
- if (!restServiceResponse.IsSuccessStatusCode)
- {
- throw new CallFailureException($"Call has been failed");
- }
- context.LogQueue.AddDebugMessage($"ICS CardSummary success for PId ending - {Common.GetLastFour(request.AccountID)}");
- var response = Common.DeSerializeObject<CreditCardSummary>(restServiceResponseInformation, false);
- return response;
- }