public async Task <ActionResult <FlightPlan> > GetFlightPlan(string id) { if (flightPlansId.Contains(id)) { return(NotFound(id)); } var flightPlan = (await this.flightPlansService.FindAsync(id)); if (flightPlan != null) { return(this.Ok(flightPlan)); } var serversList = (await this.serversController.GetApiServer()).Value; if (serversList.IsNullOrEmpty()) { return(NotFound(id)); } string issue = string.Empty; flightPlansId.Add(id); using (HttpClient client = this.httpClientFactory.CreateClient(nameof(IServerService))) { // var result = await client.GetAsync("https://"+this.Request.Host.Value + "/api/servers"); // IEnumerable<Servers> serversList = JsonConvert.DeserializeObject<IEnumerable<Servers>>(await result.Content.ReadAsStringAsync()); foreach (Server server in serversList) { try { var uri = new Uri($"{server.URL}/api/FlightPlan/{id}"); var response = await client.GetAsync(uri); var arr = await response.Content.ReadAsStringAsync(); flightPlan = JsonConvert.DeserializeObject <FlightPlan>(await response.Content.ReadAsStringAsync()); flightPlan.Id = id; if (FlightPlan.IsValidFlightPlanModel(flightPlan)) { flightPlansId.Remove(id); return(Ok(flightPlan)); } } catch (HttpRequestException httpException) { issue = httpException.Message; await Console.Error.WriteLineAsync(issue).ConfigureAwait(false); } catch (Exception exception) { // todo add logger issue = exception.Message; await Console.Error.WriteLineAsync(issue).ConfigureAwait(false); } } } flightPlansId.Remove(id); return(NotFound($"Flight with Id:'{id}' was not found\n\n\nError message: {issue}")); }