diff --git a/ShopifySharp/Infrastructure/CloneableRequestMessage.cs b/ShopifySharp/Infrastructure/CloneableRequestMessage.cs index fae1a946..3eda4851 100644 --- a/ShopifySharp/Infrastructure/CloneableRequestMessage.cs +++ b/ShopifySharp/Infrastructure/CloneableRequestMessage.cs @@ -80,18 +80,25 @@ private static async Task CloneToStreamOrReadOnlyMemoryContent(Http return clonedContent; } - public string GetRequestInfo() + public async Task GetRequestInfo() { var headers = this.Headers.Where(kv => kv.Value != null && kv.Key != ShopifyService.REQUEST_HEADER_ACCESS_TOKEN) .Select(kv => $"\t{kv.Key}: {string.Join(", ", kv.Value)}"); + var contents = this.Content switch + { + StringContent strContent => await strContent.ReadAsStringAsync(), + null => "(none)", + _ => this.Content.GetType().Name + }; + return $""" Method: {this.Method} RequestUri: {this.RequestUri} - Content: {this.Content?.GetType().Name} Headers: [ {string.Join(Environment.NewLine, headers)} ] + Content: {contents} """; } } diff --git a/ShopifySharp/Services/ShopifyService.cs b/ShopifySharp/Services/ShopifyService.cs index f0e8a87d..d0de4196 100644 --- a/ShopifySharp/Services/ShopifyService.cs +++ b/ShopifySharp/Services/ShopifyService.cs @@ -215,11 +215,11 @@ private string ReadLinkHeader(HttpResponseHeaders responseHeaders) #endif //Check for and throw exception when necessary. - CheckResponseExceptions(baseRequestMessage.GetRequestInfo(), response, rawResult); + CheckResponseExceptions(await baseRequestMessage.GetRequestInfo(), response, rawResult); var result = method == HttpMethod.Delete ? default : Serializer.Deserialize(rawResult, rootElement, dateParseHandlingOverride); - return new RequestResult(baseRequestMessage.GetRequestInfo(), response, response.Headers, result, rawResult, ReadLinkHeader(response.Headers)); + return new RequestResult(await baseRequestMessage.GetRequestInfo(), response, response.Headers, result, rawResult, ReadLinkHeader(response.Headers)); }, cancellationToken, graphqlQueryCost); return policyResult; diff --git a/ShopifySharp/Utilities/ShopifyOauthUtility.cs b/ShopifySharp/Utilities/ShopifyOauthUtility.cs index e486f9ac..c9686fb4 100644 --- a/ShopifySharp/Utilities/ShopifyOauthUtility.cs +++ b/ShopifySharp/Utilities/ShopifyOauthUtility.cs @@ -242,7 +242,7 @@ string clientSecret using var response = await client.SendAsync(request); var rawDataString = await response.Content.ReadAsStringAsync(); - ShopifyService.CheckResponseExceptions(request.GetRequestInfo(), response, rawDataString); + ShopifyService.CheckResponseExceptions(await request.GetRequestInfo(), response, rawDataString); var json = JToken.Parse(rawDataString); return new AuthorizationResult(json.Value("access_token"), json.Value("scope")?.Split(',')); @@ -285,7 +285,7 @@ string existingStoreAccessToken using var response = await client.SendAsync(request); var rawDataString = await response.Content.ReadAsStringAsync(); - ShopifyService.CheckResponseExceptions(request.GetRequestInfo(), response, rawDataString); + ShopifyService.CheckResponseExceptions(await request.GetRequestInfo(), response, rawDataString); var json = JToken.Parse(rawDataString); // TODO: throw a ShopifyJsonParseException if value is null. Exception should have a RawBody property.