Skip to content

Commit

Permalink
Use HandleRequestAsync in all requests
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriyDurov committed Aug 30, 2023
1 parent 8bafa23 commit 7daa6a2
Showing 1 changed file with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public virtual async Task<IEnumerable<TEntity>> GetAllAsync()

_logger.LogInformation("GetAll {type}: {path}", typeof(TEntity).Name, GetFullPath(path));

var msg = new HttpRequestMessage(HttpMethod.Get, path);
var result = await HandleRequestAsync<IEnumerable<TEntity>>(msg);
var message = new HttpRequestMessage(HttpMethod.Get, path);
var result = await HandleRequestAsync<IEnumerable<TEntity>>(message);

return result;
}
Expand All @@ -89,11 +89,8 @@ public virtual async Task<PageResult<TEntity>> 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<PageResult<TEntity>>(content, ServiceOptions.SerializerOptions)!;
var message = new HttpRequestMessage(HttpMethod.Get, path);
var result = await HandleRequestAsync<PageResult<TEntity>>(message);

return result;
}
Expand All @@ -104,11 +101,9 @@ public virtual async Task<TEntity> 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<TEntity>(content, ServiceOptions.SerializerOptions)!;
var message = new HttpRequestMessage(HttpMethod.Get, idEndpoint);
var result = await HandleRequestAsync<TEntity>(message);

return result;
}
Expand Down Expand Up @@ -143,10 +138,8 @@ public async Task<TEntity> 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<TEntity>(content, ServiceOptions.SerializerOptions)!;
var message = new HttpRequestMessage(HttpMethod.Get, idEndpoint);
var result = await HandleRequestAsync<TEntity>(message);

return result;
}
Expand Down

0 comments on commit 7daa6a2

Please sign in to comment.