Skip to content

Commit

Permalink
Merge pull request #1038 from clement911/master
Browse files Browse the repository at this point in the history
GetRequestInfo outputs the string content if any.
  • Loading branch information
clement911 committed Mar 7, 2024
2 parents 2818871 + e65e08b commit d941d9d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
11 changes: 9 additions & 2 deletions ShopifySharp/Infrastructure/CloneableRequestMessage.cs
Expand Up @@ -80,18 +80,25 @@ private static async Task<HttpContent> CloneToStreamOrReadOnlyMemoryContent(Http
return clonedContent;
}

public string GetRequestInfo()
public async Task<string> 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}
""";
}
}
Expand Down
4 changes: 2 additions & 2 deletions ShopifySharp/Services/ShopifyService.cs
Expand Up @@ -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<T>(rawResult, rootElement, dateParseHandlingOverride);
return new RequestResult<T>(baseRequestMessage.GetRequestInfo(), response, response.Headers, result, rawResult, ReadLinkHeader(response.Headers));
return new RequestResult<T>(await baseRequestMessage.GetRequestInfo(), response, response.Headers, result, rawResult, ReadLinkHeader(response.Headers));
}, cancellationToken, graphqlQueryCost);

return policyResult;
Expand Down
4 changes: 2 additions & 2 deletions ShopifySharp/Utilities/ShopifyOauthUtility.cs
Expand Up @@ -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<string>("access_token"), json.Value<string>("scope")?.Split(','));

Check warning on line 248 in ShopifySharp/Utilities/ShopifyOauthUtility.cs

View workflow job for this annotation

GitHub Actions / Build

Possible null reference argument for parameter 'accessToken' in 'AuthorizationResult.AuthorizationResult(string accessToken, string[]? grantedScopes)'.

Check warning on line 248 in ShopifySharp/Utilities/ShopifyOauthUtility.cs

View workflow job for this annotation

GitHub Actions / Unit tests

Possible null reference argument for parameter 'accessToken' in 'AuthorizationResult.AuthorizationResult(string accessToken, string[]? grantedScopes)'.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit d941d9d

Please sign in to comment.