diff --git a/GraphQLSharp/Client/Exceptions/GraphQLHttpException.cs b/GraphQLSharp/Client/Exceptions/GraphQLHttpException.cs index 5b10bd2..c88e49f 100644 --- a/GraphQLSharp/Client/Exceptions/GraphQLHttpException.cs +++ b/GraphQLSharp/Client/Exceptions/GraphQLHttpException.cs @@ -2,19 +2,11 @@ namespace GraphQLSharp; public class GraphQLHttpException : GraphQLException { - public IReadOnlyList Errors { get; } - public GraphQLHttpException(GraphQLRequest request, HttpResponse httpResponse, Exception ex) - : this(new GraphQLHttpError { Request = request, HttpResponse = httpResponse }, ex) - { - } - - public GraphQLHttpException(GraphQLHttpError error, Exception ex) - : base(error.Request, error.HttpResponse, $""" - GraphQL request failed with an HTTP error: {(error.errors != null ? string.Join("\n", error.errors) : "")} - Request: {error.Request} + : base(request, httpResponse, $""" + GraphQL request failed with an HTTP error: + Request: {request} """, ex) { - Errors = Array.AsReadOnly(error.errors?.ToArray() ?? Array.Empty()); } -} +} \ No newline at end of file diff --git a/GraphQLSharp/Client/GraphQLClient.cs b/GraphQLSharp/Client/GraphQLClient.cs index 575aced..e986605 100644 --- a/GraphQLSharp/Client/GraphQLClient.cs +++ b/GraphQLSharp/Client/GraphQLClient.cs @@ -102,20 +102,7 @@ private async Task> ExecuteCoreAsync(TRequest request, Can } catch (Exception httpEx) { - GraphQLHttpError gqlHttpError = null; - try - { - gqlHttpError = await httpResponseMsg.Content.ReadFromJsonAsync(_options.JsonSerializerOptions ?? Serializer.GetOptions(), - cancellationToken); - } - catch (Exception errorDetailsException) when (errorDetailsException is JsonException or InvalidOperationException) - { - // Error details are optional; preserve the HTTP failure for callers and retries. - } - gqlHttpError ??= new GraphQLHttpError(); - gqlHttpError.Request = request; - gqlHttpError.HttpResponse = httpResponse; - throw new GraphQLHttpException(gqlHttpError, httpEx); + throw new GraphQLHttpException(request, httpResponse, httpEx); } GraphQLResponse res; @@ -161,4 +148,4 @@ private HttpRequestMessage CreateHttpRequest(TRequest request, HttpClient httpCl _options.ConfigureHttpRequestHeaders?.Invoke(requestMessage.Headers); return requestMessage; } -} +} \ No newline at end of file diff --git a/GraphQLSharp/Client/Response/GraphQLHttpError.cs b/GraphQLSharp/Client/Response/GraphQLHttpError.cs deleted file mode 100644 index 49202d7..0000000 --- a/GraphQLSharp/Client/Response/GraphQLHttpError.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Text.Json.Serialization; - -namespace GraphQLSharp; - -public class GraphQLHttpError : IGraphQLObject -{ - [JsonIgnore] - public GraphQLRequest Request { get; internal set; } - - [JsonIgnore] - public HttpResponse HttpResponse { get; internal set; } - - [JsonConverter(typeof(GraphQLHttpErrorMessageConverter))] - public List errors { get; set; } -} diff --git a/GraphQLSharp/GraphQLSharp.csproj b/GraphQLSharp/GraphQLSharp.csproj index 850abf9..06cf8c8 100644 --- a/GraphQLSharp/GraphQLSharp.csproj +++ b/GraphQLSharp/GraphQLSharp.csproj @@ -4,7 +4,7 @@ https://github.com/Wish-Org/GraphQLSharp https://github.com/Wish-Org/GraphQLSharp .NET Client for GraphQL - Modern and fast - 2.24.0 + 2.23.0 graphql;client;graphql-client;graphql-generator Wish-Org README.md diff --git a/GraphQLSharp/Serialization/GraphQLHttpErrorMessageConverter.cs b/GraphQLSharp/Serialization/GraphQLHttpErrorMessageConverter.cs deleted file mode 100644 index cf8257b..0000000 --- a/GraphQLSharp/Serialization/GraphQLHttpErrorMessageConverter.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Text.Json; -using System.Text.Json.Serialization; - -namespace GraphQLSharp; - -// Normalizes the value of an HTTP error response's "errors" property into individual messages: -// "Service unavailable" -> one message -// ["First error", "Second error"] -> multiple messages -// [{"message":"First"}, {"message":"Second"}] -> GraphQL error object messages -// Arrays may mix strings and error objects; message order is preserved. -// JSON null is handled by System.Text.Json and remains null. -internal sealed class GraphQLHttpErrorMessageConverter : JsonConverter> -{ - public override List Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - if (reader.TokenType == JsonTokenType.String) - return [reader.GetString()]; - - using var document = JsonDocument.ParseValue(ref reader); - var errors = document.RootElement; - if (errors.ValueKind != JsonValueKind.Array) - return null; - - var messages = new List(); - foreach (var error in errors.EnumerateArray()) - { - if (error.ValueKind == JsonValueKind.String) - messages.Add(error.GetString()); - else if (error.ValueKind == JsonValueKind.Object - && error.TryGetProperty("message", out var message) - && message.ValueKind == JsonValueKind.String) - messages.Add(message.GetString()); - } - return messages; - } - - public override void Write(Utf8JsonWriter writer, List value, JsonSerializerOptions options) - { - // Non-null lists are always written as JSON string arrays, regardless of the input format. - writer.WriteStartArray(); - foreach (var message in value) - writer.WriteStringValue(message); - writer.WriteEndArray(); - } -}