4040 * {@link DataFetcherExceptionHandler} that invokes {@link DataFetcherExceptionResolver}'s
4141 * in a sequence until one returns a list of {@link GraphQLError}'s.
4242 *
43+ * <p>Use {@link DataFetcherExceptionResolver#createExceptionHandler(List)} to
44+ * create an instance.
45+ *
4346 * @author Rossen Stoyanchev
4447 */
4548class ExceptionResolversExceptionHandler implements DataFetcherExceptionHandler {
4649
4750 private static final Log logger = LogFactory .getLog (ExceptionResolversExceptionHandler .class );
4851
52+
4953 private final List <DataFetcherExceptionResolver > resolvers ;
5054
55+
5156 /**
5257 * Create an instance.
5358 * @param resolvers the resolvers to use
@@ -59,9 +64,11 @@ class ExceptionResolversExceptionHandler implements DataFetcherExceptionHandler
5964
6065
6166 @ Override
62- public CompletableFuture <DataFetcherExceptionHandlerResult > handleException (DataFetcherExceptionHandlerParameters params ) {
63- Throwable exception = unwrapException (params );
64- DataFetchingEnvironment env = params .getDataFetchingEnvironment ();
67+ public CompletableFuture <DataFetcherExceptionHandlerResult > handleException (
68+ DataFetcherExceptionHandlerParameters handlerParameters ) {
69+
70+ Throwable exception = unwrapException (handlerParameters );
71+ DataFetchingEnvironment env = handlerParameters .getDataFetchingEnvironment ();
6572 ContextSnapshot snapshot = ContextSnapshotFactoryHelper .captureFrom (env .getGraphQlContext ());
6673 try {
6774 return Flux .fromIterable (this .resolvers )
@@ -79,34 +86,34 @@ public CompletableFuture<DataFetcherExceptionHandlerResult> handleException(Data
7986 }
8087 }
8188
82- private DataFetcherExceptionHandlerResult handleResolverError (
83- Throwable resolverException , Throwable originalException , DataFetchingEnvironment environment ) {
84-
85- if (logger .isWarnEnabled ()) {
86- logger .warn ("Failure while resolving " + originalException .getMessage (), resolverException );
87- }
88- return createInternalError (originalException , environment );
89- }
90-
9189 private Throwable unwrapException (DataFetcherExceptionHandlerParameters params ) {
9290 Throwable ex = params .getException ();
9391 return ((ex instanceof CompletionException ) ? ex .getCause () : ex );
9492 }
9593
9694 private void logResolvedException (Throwable ex , DataFetcherExceptionHandlerResult result ) {
9795 if (logger .isDebugEnabled ()) {
98- logger .debug ("Resolved " + ex .getClass ().getSimpleName () +
99- " to GraphQL error(s): " + result .getErrors (), ex );
96+ String name = ex .getClass ().getSimpleName ();
97+ logger .debug ("Resolved " + name + " to GraphQL error(s): " + result .getErrors (), ex );
98+ }
99+ }
100+
101+ private DataFetcherExceptionHandlerResult handleResolverError (
102+ Throwable resolverException , Throwable originalException , DataFetchingEnvironment env ) {
103+
104+ if (logger .isWarnEnabled ()) {
105+ logger .warn ("Failure while resolving " + originalException .getMessage (), resolverException );
100106 }
107+ return createInternalError (originalException , env );
101108 }
102109
103- private DataFetcherExceptionHandlerResult createInternalError (Throwable ex , DataFetchingEnvironment environment ) {
104- ExecutionId executionId = environment .getExecutionId ();
110+ private DataFetcherExceptionHandlerResult createInternalError (Throwable ex , DataFetchingEnvironment env ) {
111+ ExecutionId executionId = env .getExecutionId ();
105112 if (logger .isErrorEnabled ()) {
106113 logger .error ("Unresolved " + ex .getClass ().getSimpleName () + " for executionId " + executionId , ex );
107114 }
108115 return DataFetcherExceptionHandlerResult
109- .newResult (GraphqlErrorBuilder .newError (environment )
116+ .newResult (GraphqlErrorBuilder .newError (env )
110117 .errorType (ErrorType .INTERNAL_ERROR )
111118 .message (ErrorType .INTERNAL_ERROR + " for " + executionId )
112119 .build ())
0 commit comments