|
1 | 1 | package graphql.kickstart.servlet; |
2 | 2 |
|
| 3 | +import static graphql.kickstart.servlet.HttpRequestHandler.STATUS_BAD_REQUEST; |
| 4 | +import static graphql.kickstart.servlet.HttpRequestHandler.STATUS_INTERNAL_SERVER_ERROR; |
| 5 | + |
3 | 6 | import graphql.ExecutionResult; |
4 | 7 | import graphql.ExecutionResultImpl; |
| 8 | +import graphql.GraphQLException; |
5 | 9 | import graphql.kickstart.execution.FutureExecutionResult; |
6 | 10 | import graphql.kickstart.execution.GraphQLInvoker; |
7 | 11 | import graphql.kickstart.execution.GraphQLQueryResult; |
@@ -76,10 +80,22 @@ private void invokeAndHandleAsync( |
76 | 80 | .getAsyncExecutor() |
77 | 81 | .execute( |
78 | 82 | () -> { |
79 | | - FutureExecutionResult futureResult = invoke(invocationInput, request, response); |
80 | | - futureHolder.set(futureResult); |
81 | | - handle(futureResult, request, response, listenerHandler) |
82 | | - .thenAccept(it -> asyncContext.complete()); |
| 83 | + try { |
| 84 | + FutureExecutionResult futureResult = invoke(invocationInput, request, response); |
| 85 | + futureHolder.set(futureResult); |
| 86 | + handle(futureResult, request, response, listenerHandler) |
| 87 | + .thenAccept(it -> asyncContext.complete()); |
| 88 | + } catch (GraphQLException e) { |
| 89 | + response.setStatus(STATUS_BAD_REQUEST); |
| 90 | + log.info("Bad request: cannot handle http request", e); |
| 91 | + listenerHandler.onError(e); |
| 92 | + asyncContext.complete(); |
| 93 | + } catch (Exception e) { |
| 94 | + response.setStatus(STATUS_INTERNAL_SERVER_ERROR); |
| 95 | + log.error("Cannot handle http request", e); |
| 96 | + listenerHandler.onError(e); |
| 97 | + asyncContext.complete(); |
| 98 | + } |
83 | 99 | }); |
84 | 100 | } |
85 | 101 |
|
|
0 commit comments