Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetRequestInfo outputs the string content if any. #1038

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions ShopifySharp/Infrastructure/CloneableRequestMessage.cs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ protected async Task<RequestResult<T>> ExecuteRequestCoreAsync<T>(
#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
Original file line number Diff line number Diff line change
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(','));
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