Skip to content

Commit

Permalink
fix: handle exception in async mode fixes #403
Browse files Browse the repository at this point in the history
  • Loading branch information
oliemansm committed Jan 23, 2022
1 parent bb276e1 commit 1d876ef
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package graphql.kickstart.servlet;

import static graphql.kickstart.servlet.HttpRequestHandler.STATUS_BAD_REQUEST;
import static graphql.kickstart.servlet.HttpRequestHandler.STATUS_INTERNAL_SERVER_ERROR;

import graphql.ExecutionResult;
import graphql.ExecutionResultImpl;
import graphql.GraphQLException;
import graphql.kickstart.execution.FutureExecutionResult;
import graphql.kickstart.execution.GraphQLInvoker;
import graphql.kickstart.execution.GraphQLQueryResult;
Expand Down Expand Up @@ -76,10 +80,22 @@ private void invokeAndHandleAsync(
.getAsyncExecutor()
.execute(
() -> {
FutureExecutionResult futureResult = invoke(invocationInput, request, response);
futureHolder.set(futureResult);
handle(futureResult, request, response, listenerHandler)
.thenAccept(it -> asyncContext.complete());
try {
FutureExecutionResult futureResult = invoke(invocationInput, request, response);
futureHolder.set(futureResult);
handle(futureResult, request, response, listenerHandler)
.thenAccept(it -> asyncContext.complete());
} catch (GraphQLException e) {
response.setStatus(STATUS_BAD_REQUEST);
log.info("Bad request: cannot handle http request", e);
listenerHandler.onError(e);
asyncContext.complete();
} catch (Exception e) {
response.setStatus(STATUS_INTERNAL_SERVER_ERROR);
log.error("Cannot handle http request", e);
listenerHandler.onError(e);
asyncContext.complete();
}
});
}

Expand Down

0 comments on commit 1d876ef

Please sign in to comment.