11package graphql .execution ;
22
33import graphql .ExceptionWhileDataFetching ;
4- import graphql .GraphQLError ;
54import graphql .PublicApi ;
5+ import graphql .language .SourceLocation ;
66import graphql .util .LogKit ;
77import org .slf4j .Logger ;
88
9- import java .util .concurrent .CompletionException ;
10-
119/**
1210 * The standard handling of data fetcher error involves placing a {@link ExceptionWhileDataFetching} error
1311 * into the error collection
@@ -19,28 +17,13 @@ public class SimpleDataFetcherExceptionHandler implements DataFetcherExceptionHa
1917
2018 @ Override
2119 public DataFetcherExceptionHandlerResult onException (DataFetcherExceptionHandlerParameters handlerParameters ) {
22- Throwable exception = unwrap (handlerParameters .getException ());
23- GraphQLError error ;
24- if (exception instanceof GraphQLError ) {
25- error = (GraphQLError ) exception ;
26- } else {
27- error = new ExceptionWhileDataFetching (handlerParameters .getPath (), exception , handlerParameters .getSourceLocation ());
28- }
20+ Throwable exception = handlerParameters .getException ();
21+ SourceLocation sourceLocation = handlerParameters .getSourceLocation ();
22+ ResultPath path = handlerParameters .getPath ();
23+
24+ ExceptionWhileDataFetching error = new ExceptionWhileDataFetching (path , exception , sourceLocation );
2925 logNotSafe .warn (error .getMessage (), exception );
30- return DataFetcherExceptionHandlerResult .newResult ().error (error ).build ();
31- }
3226
33- /**
34- * Called to unwrap an exception to a more suitable cause if required
35- *
36- * @param exception the exception to unwrap
37- *
38- * @return the suitable exception
39- */
40- protected Throwable unwrap (Throwable exception ) {
41- if (exception instanceof CompletionException ) {
42- return exception .getCause ();
43- }
44- return exception ;
27+ return DataFetcherExceptionHandlerResult .newResult ().error (error ).build ();
4528 }
4629}
0 commit comments