-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return RawBody from Create/GetOrder methods
- Loading branch information
o.nadymov
committed
Jul 19, 2024
1 parent
197ec7b
commit 4026eb1
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |