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

Add exception handling for synchronous execution #442

Merged
merged 2 commits into from
Jul 21, 2022
Merged
Changes from 1 commit
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 @@ -45,7 +45,7 @@ public void execute(
if (request.isAsyncSupported()) {
invokeAndHandleAsync(invocationInput, request, response, listenerHandler);
} else {
handle(invoke(invocationInput, request, response), request, response, listenerHandler).join();
handle(invocationInput, request, response, listenerHandler);
}
}

Expand Down Expand Up @@ -83,7 +83,7 @@ private void invokeAndHandleAsync(
try {
FutureExecutionResult futureResult = invoke(invocationInput, request, response);
futureHolder.set(futureResult);
handle(futureResult, request, response, listenerHandler)
handle0(futureResult, request, response, listenerHandler)
.thenAccept(it -> asyncContext.complete());
} catch (GraphQLException e) {
response.setStatus(STATUS_BAD_REQUEST);
Expand All @@ -99,7 +99,26 @@ private void invokeAndHandleAsync(
});
}

private CompletableFuture<Void> handle(
private void handle(
GraphQLInvocationInput invocationInput,
HttpServletRequest request,
HttpServletResponse response,
ListenerHandler listenerHandler) {
try {
FutureExecutionResult futureResult = invoke(invocationInput, request, response);
handle0(futureResult, request, response, listenerHandler);
} catch (GraphQLException e) {
response.setStatus(STATUS_BAD_REQUEST);
log.info("Bad request: cannot handle http request", e);
listenerHandler.onError(e);
} catch (Exception e) {
response.setStatus(STATUS_INTERNAL_SERVER_ERROR);
log.error("Cannot handle http request", e);
listenerHandler.onError(e);
}
}

private CompletableFuture<Void> handle0(
heowc marked this conversation as resolved.
Show resolved Hide resolved
FutureExecutionResult futureResult,
HttpServletRequest request,
HttpServletResponse response,
Expand Down