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
@@ -60,9 +65,11 @@ class ExceptionResolversExceptionHandler implements DataFetcherExceptionHandler
6065
6166 @ Override
6267 @ SuppressWarnings ("deprecation" )
63- public CompletableFuture <DataFetcherExceptionHandlerResult > handleException (DataFetcherExceptionHandlerParameters params ) {
64- Throwable exception = unwrapException (params );
65- DataFetchingEnvironment env = params .getDataFetchingEnvironment ();
68+ public CompletableFuture <DataFetcherExceptionHandlerResult > handleException (
69+ DataFetcherExceptionHandlerParameters handlerParameters ) {
70+
71+ Throwable exception = unwrapException (handlerParameters );
72+ DataFetchingEnvironment env = handlerParameters .getDataFetchingEnvironment ();
6673 ContextSnapshot snapshot = ContextSnapshot .captureFrom (env .getGraphQlContext ());
6774 try {
6875 return Flux .fromIterable (this .resolvers )
@@ -80,34 +87,34 @@ public CompletableFuture<DataFetcherExceptionHandlerResult> handleException(Data
8087 }
8188 }
8289
83- private DataFetcherExceptionHandlerResult handleResolverError (
84- Throwable resolverException , Throwable originalException , DataFetchingEnvironment environment ) {
85-
86- if (logger .isWarnEnabled ()) {
87- logger .warn ("Failure while resolving " + originalException .getMessage (), resolverException );
88- }
89- return createInternalError (originalException , environment );
90- }
91-
9290 private Throwable unwrapException (DataFetcherExceptionHandlerParameters params ) {
9391 Throwable ex = params .getException ();
9492 return ((ex instanceof CompletionException ) ? ex .getCause () : ex );
9593 }
9694
9795 private void logResolvedException (Throwable ex , DataFetcherExceptionHandlerResult result ) {
9896 if (logger .isDebugEnabled ()) {
99- logger .debug ("Resolved " + ex .getClass ().getSimpleName () +
100- " to GraphQL error(s): " + result .getErrors (), ex );
97+ String name = ex .getClass ().getSimpleName ();
98+ logger .debug ("Resolved " + name + " to GraphQL error(s): " + result .getErrors (), ex );
99+ }
100+ }
101+
102+ private DataFetcherExceptionHandlerResult handleResolverError (
103+ Throwable resolverException , Throwable originalException , DataFetchingEnvironment env ) {
104+
105+ if (logger .isWarnEnabled ()) {
106+ logger .warn ("Failure while resolving " + originalException .getMessage (), resolverException );
101107 }
108+ return createInternalError (originalException , env );
102109 }
103110
104- private DataFetcherExceptionHandlerResult createInternalError (Throwable ex , DataFetchingEnvironment environment ) {
105- ExecutionId executionId = environment .getExecutionId ();
111+ private DataFetcherExceptionHandlerResult createInternalError (Throwable ex , DataFetchingEnvironment env ) {
112+ ExecutionId executionId = env .getExecutionId ();
106113 if (logger .isErrorEnabled ()) {
107114 logger .error ("Unresolved " + ex .getClass ().getSimpleName () + " for executionId " + executionId , ex );
108115 }
109116 return DataFetcherExceptionHandlerResult
110- .newResult (GraphqlErrorBuilder .newError (environment )
117+ .newResult (GraphqlErrorBuilder .newError (env )
111118 .errorType (ErrorType .INTERNAL_ERROR )
112119 .message (ErrorType .INTERNAL_ERROR + " for " + executionId )
113120 .build ())
0 commit comments