From dfcf1fb5366fa66f0aa5ecd74372ffa9f19491b1 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 19 May 2026 18:57:21 +0200 Subject: [PATCH] Refactor BaseCrudApi methods to improve error handling Updated `CreateAsync`, `UpdateAsync`, and `DeleteAsync` methods to return `Task` instead of `Task`. Removed `` documentation and added `` tags to indicate that a `ReCApiException` is thrown for non-successful API responses. Replaced `resp.IsSuccessStatusCode` checks with `ReCClientHelpers.EnsureSuccessAsync` to enforce exception-based error handling. These changes align with modern asynchronous error-handling practices. --- src/ReC.Client/Api/BaseCrudApi.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ReC.Client/Api/BaseCrudApi.cs b/src/ReC.Client/Api/BaseCrudApi.cs index c5f450d..a6c4cbe 100644 --- a/src/ReC.Client/Api/BaseCrudApi.cs +++ b/src/ReC.Client/Api/BaseCrudApi.cs @@ -37,13 +37,13 @@ namespace ReC.Client.Api /// The payload type. /// The payload to send. /// A token to cancel the operation. - /// if the request succeeds; otherwise, . - public async Task CreateAsync(T payload, CancellationToken cancel = default) + /// Thrown when the API responds with a non-success status code. + public async Task CreateAsync(T payload, CancellationToken cancel = default) { using (var content = ReCClientHelpers.ToJsonContent(payload)) using (var resp = await Http.PostAsync(ResourcePath, content, cancel)) { - return resp.IsSuccessStatusCode; + await ReCClientHelpers.EnsureSuccessAsync(resp, cancel).ConfigureAwait(false); } } @@ -54,13 +54,13 @@ namespace ReC.Client.Api /// The resource identifier. /// The payload to send. /// A token to cancel the operation. - /// if the request succeeds; otherwise, . - public async Task UpdateAsync(long id, T payload, CancellationToken cancel = default) + /// Thrown when the API responds with a non-success status code. + public async Task UpdateAsync(long id, T payload, CancellationToken cancel = default) { using (var content = ReCClientHelpers.ToJsonContent(payload)) using (var resp = await Http.PutAsync($"{ResourcePath}/{id}", content, cancel)) { - return resp.IsSuccessStatusCode; + await ReCClientHelpers.EnsureSuccessAsync(resp, cancel).ConfigureAwait(false); } } @@ -70,8 +70,8 @@ namespace ReC.Client.Api /// The payload type containing identifiers. /// The payload to send. /// A token to cancel the operation. - /// if the request succeeds; otherwise, . - public async Task DeleteAsync(T payload, CancellationToken cancel = default) + /// Thrown when the API responds with a non-success status code. + public async Task DeleteAsync(T payload, CancellationToken cancel = default) { using (var request = new HttpRequestMessage(HttpMethod.Delete, ResourcePath) { @@ -79,7 +79,7 @@ namespace ReC.Client.Api }) using (var resp = await Http.SendAsync(request, cancel)) { - return resp.IsSuccessStatusCode; + await ReCClientHelpers.EnsureSuccessAsync(resp, cancel).ConfigureAwait(false); } } }