1111import io .spring .api .exception .InvalidAuthenticationException ;
1212import io .spring .graphql .types .Error ;
1313import io .spring .graphql .types .ErrorItem ;
14+ import jakarta .validation .ConstraintViolation ;
15+ import jakarta .validation .ConstraintViolationException ;
1416import java .util .ArrayList ;
1517import java .util .Arrays ;
1618import java .util .HashMap ;
1719import java .util .List ;
1820import java .util .Map ;
21+ import java .util .concurrent .CompletableFuture ;
1922import java .util .stream .Collectors ;
20- import jakarta .validation .ConstraintViolation ;
21- import jakarta .validation .ConstraintViolationException ;
2223import org .springframework .stereotype .Component ;
2324
2425@ Component
@@ -28,7 +29,7 @@ public class GraphQLCustomizeExceptionHandler implements DataFetcherExceptionHan
2829 new DefaultDataFetcherExceptionHandler ();
2930
3031 @ Override
31- public DataFetcherExceptionHandlerResult onException (
32+ public CompletableFuture < DataFetcherExceptionHandlerResult > handleException (
3233 DataFetcherExceptionHandlerParameters handlerParameters ) {
3334 if (handlerParameters .getException () instanceof InvalidAuthenticationException ) {
3435 GraphQLError graphqlError =
@@ -37,7 +38,8 @@ public DataFetcherExceptionHandlerResult onException(
3738 .message (handlerParameters .getException ().getMessage ())
3839 .path (handlerParameters .getPath ())
3940 .build ();
40- return DataFetcherExceptionHandlerResult .newResult ().error (graphqlError ).build ();
41+ return CompletableFuture .completedFuture (
42+ DataFetcherExceptionHandlerResult .newResult ().error (graphqlError ).build ());
4143 } else if (handlerParameters .getException () instanceof ConstraintViolationException ) {
4244 List <FieldErrorResource > errors = new ArrayList <>();
4345 for (ConstraintViolation <?> violation :
@@ -61,9 +63,10 @@ public DataFetcherExceptionHandlerResult onException(
6163 .path (handlerParameters .getPath ())
6264 .extensions (errorsToMap (errors ))
6365 .build ();
64- return DataFetcherExceptionHandlerResult .newResult ().error (graphqlError ).build ();
66+ return CompletableFuture .completedFuture (
67+ DataFetcherExceptionHandlerResult .newResult ().error (graphqlError ).build ());
6568 } else {
66- return defaultHandler .onException (handlerParameters );
69+ return defaultHandler .handleException (handlerParameters );
6770 }
6871 }
6972
0 commit comments