public async Task<Product> GetProduct(string uri, HttpClient httpClient) { using var httpResponse = await httpClient.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead); httpResponse.EnsureSuccessStatusCode(); if (httpResponse.Content is object && httpResponse.Content.Headers.ContentType.MediaType == "application/json") { var contentStream = await httpResponse.Content.ReadAsStreamAsync(); try { return await System.Text.Json.JsonSerializer.DeserializeAsync<Product>(contentStream, new System.Text.Json.JsonSerializerOptions { IgnoreNullValues = true, PropertyNameCaseInsensitive = true }); } catch (JsonException ex) { _logger.LogError(ex, "Error fetching product."); } } return null; }