diff --git a/src/BitzArt.Communicator.REST/Models/CommunicatorRestEntityContext.cs b/src/BitzArt.Communicator.REST/Models/CommunicatorRestEntityContext.cs index 110c8d3..02f4b42 100644 --- a/src/BitzArt.Communicator.REST/Models/CommunicatorRestEntityContext.cs +++ b/src/BitzArt.Communicator.REST/Models/CommunicatorRestEntityContext.cs @@ -64,8 +64,8 @@ public virtual async Task> GetAllAsync() _logger.LogInformation("GetAll {type}: {path}", typeof(TEntity).Name, GetFullPath(path)); - var msg = new HttpRequestMessage(HttpMethod.Get, path); - var result = await HandleRequestAsync>(msg); + var message = new HttpRequestMessage(HttpMethod.Get, path); + var result = await HandleRequestAsync>(message); return result; } @@ -89,11 +89,8 @@ public virtual async Task> GetPageAsync(PageRequest pageRequ _logger.LogInformation("GetPage {type}: {path}", typeof(TEntity).Name, GetFullPath(path)); - var response = await HttpClient.GetAsync(path); - - if (!response.IsSuccessStatusCode) throw new Exception($"External REST Service responded with http status code '{response.StatusCode}'."); - var content = await response.Content.ReadAsStringAsync(); - var result = JsonSerializer.Deserialize>(content, ServiceOptions.SerializerOptions)!; + var message = new HttpRequestMessage(HttpMethod.Get, path); + var result = await HandleRequestAsync>(message); return result; } @@ -104,11 +101,9 @@ public virtual async Task GetAsync(object id) var idEndpoint = EntityOptions.GetIdEndpointAction(id); _logger.LogInformation("Get {type}[{id}]: {path}", typeof(TEntity).Name, id.ToString(), GetFullPath(idEndpoint)); - var response = await HttpClient.GetAsync(idEndpoint); - if (!response.IsSuccessStatusCode) throw new Exception($"External REST Service responded with http status code '{response.StatusCode}'."); - var content = await response.Content.ReadAsStringAsync(); - var result = JsonSerializer.Deserialize(content, ServiceOptions.SerializerOptions)!; + var message = new HttpRequestMessage(HttpMethod.Get, idEndpoint); + var result = await HandleRequestAsync(message); return result; } @@ -143,10 +138,8 @@ public async Task GetAsync(TKey id) _logger.LogInformation("Get {type}[{id}]: {path}", typeof(TEntity).Name, id!.ToString(), GetFullPath(idEndpoint)); - var response = await HttpClient.GetAsync(idEndpoint); - if (!response.IsSuccessStatusCode) throw new Exception($"External REST Service responded with http status code '{response.StatusCode}'."); - var content = await response.Content.ReadAsStringAsync(); - var result = JsonSerializer.Deserialize(content, ServiceOptions.SerializerOptions)!; + var message = new HttpRequestMessage(HttpMethod.Get, idEndpoint); + var result = await HandleRequestAsync(message); return result; }