Skip to content

Commit

Permalink
Return RawBody from Create/GetOrder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
o.nadymov committed Jul 19, 2024
1 parent 197ec7b commit 4026eb1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Spoleto.RestClient/Extensions/RestClientExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Spoleto.RestClient.Serializers;

namespace Spoleto.RestClient
{
public static class RestClientExtensions
{
public static async Task<(T Object, string RawBody)> ExecuteWithRawBodyAsync<T>(this IRestClient client, RestRequest request, CancellationToken cancellationToken = default) where T : class
{
var restResponse = await client.ExecuteAsStringAsync(request, cancellationToken).ConfigureAwait(false);

if (restResponse == null)
{
throw new ArgumentNullException(nameof(restResponse));
}

if (!restResponse.IsSuccessStatusCode)
{
throw new Exception($"Unsuccesful response with {nameof(restResponse.StatusCode)} = {restResponse.StatusCode}");
}

var objectResult = SerializationManager.Deserialize<T>(restResponse);

return (objectResult, restResponse.Content);
}
}
}

0 comments on commit 4026eb1

Please sign in to comment.