-
Notifications
You must be signed in to change notification settings - Fork 135
Closed
Milestone
Description
I'm having a hard time to read the Content from the HttpResponseMessage inside the GraphQLHttpException. The code is throwing AggregateException, which holds the InnerExceptions property of type GraphQLHttpException. When I try to read the Content to figure out why my request is not working .net says the object has been disposed respectively, which is also ok as the client is implemented as a singleton. Why singleton? As far as I understood tthe graphql-client is a wrapper around HttpClient, which should be instantiated as singletons due to some internal bug(s).
This is what I tried, but no results:
try
{
var request = new GraphQLRequest()
{
Query = CreateQuery(query)
};
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer","token_goes_here");
client.Options = new GraphQLClientOptions()
{
MediaType = new MediaTypeHeaderValue("application/json"),
EndPoint = new Uri(listingImagesGraphqlUrl, UriKind.Absolute)
};
var result = client.PostAsync(request).Result;
if (result.Errors.Any())
{
var unprocessedIds = result.Errors.Select(x => x.AdditonalEntries)
.Where(y => y.ContainsKey("extensions")).Where(z => z.ContainsKey("unprocessedIds"));
}
}
catch (AggregateException exception)
{
Logging.WriteError(exception);
var ex = (GraphQLHttpException) exception.InnerExceptions[0];
Console.WriteLine(ex.HttpResponseMessage.Content.ReadAsStringAsync());
throw;
}
Is it possible to read the response body somehow?