public async Task <IDictionary <string, JobSummary> > GetLatestJobs(IEnumerable <string> jobTypes, string specificationId = null) { ApiResponse <IDictionary <string, JobSummary> > jobSummaryResponse = await _jobsApiClientPolicy.ExecuteAsync(() => specificationId != null? _jobsApiClient.GetLatestJobsForSpecification(specificationId, jobTypes.ToArray()) : _jobsApiClient.GetLatestJobsByJobDefinitionIds(jobTypes.ToArray())); if (jobSummaryResponse?.StatusCode == HttpStatusCode.NotFound || ((int?)jobSummaryResponse?.StatusCode >= 200 && (int?)jobSummaryResponse?.StatusCode <= 299)) { return(jobSummaryResponse?.Content); } else { string message = specificationId != null ? $"Error while retrieving latest jobs for Specifiation: {specificationId} and JobTypes: {string.Join(',', jobTypes)}" : $"Error while retrieving latest jobs for JobTypes: {string.Join(',', jobTypes)}"; throw new JobsNotRetrievedException(message, jobTypes, specificationId); } }