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

Better error on unparseable GraphQL JSON request #32349

Merged
merged 1 commit into from
Apr 3, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
import jakarta.json.JsonObject;
import jakarta.json.JsonObjectBuilder;
import jakarta.json.JsonReader;
import jakarta.json.stream.JsonParsingException;

import org.jboss.logging.Logger;

import graphql.ErrorType;
import graphql.ExecutionResult;
import graphql.ExecutionResultImpl;
import graphql.GraphQLError;
import graphql.GraphqlErrorBuilder;
import graphql.execution.AbortExecutionException;
import io.quarkus.security.identity.CurrentIdentityAssociation;
import io.quarkus.vertx.http.runtime.CurrentVertxRequest;
Expand Down Expand Up @@ -122,6 +125,8 @@ private void handlePost(HttpServerResponse response, RoutingContext ctx, String
}
} catch (IOException ex) {
throw new RuntimeException(ex);
} catch (JsonParsingException ex) {
sendError("Unparseable request", response, ctx, requestedCharset);
}
}

Expand Down Expand Up @@ -299,6 +304,21 @@ private String getAllowedMethods() {
}
}

private void sendError(String errorMessage, HttpServerResponse response,
RoutingContext ctx, String requestedCharset) {
VertxExecutionResponseWriter writer = new VertxExecutionResponseWriter(response, ctx, requestedCharset);
GraphQLError error = GraphqlErrorBuilder
.newError()
.message(errorMessage)
.build();
ExecutionResult executionResult = ExecutionResultImpl
.newExecutionResult()
.addError(error)
.build();
ExecutionResponse executionResponse = new ExecutionResponse(executionResult);
writer.write(executionResponse);
}

private void doRequest(JsonObject jsonInput, HttpServerResponse response, RoutingContext ctx,
String requestedCharset) {
VertxExecutionResponseWriter writer = new VertxExecutionResponseWriter(response, ctx, requestedCharset);
Expand Down