40
40
* {@link DataFetcherExceptionHandler} that invokes {@link DataFetcherExceptionResolver}'s
41
41
* in a sequence until one returns a list of {@link GraphQLError}'s.
42
42
*
43
+ * <p>Use {@link DataFetcherExceptionResolver#createExceptionHandler(List)} to
44
+ * create an instance.
45
+ *
43
46
* @author Rossen Stoyanchev
44
47
*/
45
48
class ExceptionResolversExceptionHandler implements DataFetcherExceptionHandler {
46
49
47
50
private static final Log logger = LogFactory .getLog (ExceptionResolversExceptionHandler .class );
48
51
52
+
49
53
private final List <DataFetcherExceptionResolver > resolvers ;
50
54
55
+
51
56
/**
52
57
* Create an instance.
53
58
* @param resolvers the resolvers to use
@@ -59,9 +64,11 @@ class ExceptionResolversExceptionHandler implements DataFetcherExceptionHandler
59
64
60
65
61
66
@ 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 ();
65
72
ContextSnapshot snapshot = ContextSnapshotFactoryHelper .captureFrom (env .getGraphQlContext ());
66
73
try {
67
74
return Flux .fromIterable (this .resolvers )
@@ -79,34 +86,34 @@ public CompletableFuture<DataFetcherExceptionHandlerResult> handleException(Data
79
86
}
80
87
}
81
88
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
-
91
89
private Throwable unwrapException (DataFetcherExceptionHandlerParameters params ) {
92
90
Throwable ex = params .getException ();
93
91
return ((ex instanceof CompletionException ) ? ex .getCause () : ex );
94
92
}
95
93
96
94
private void logResolvedException (Throwable ex , DataFetcherExceptionHandlerResult result ) {
97
95
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 );
100
106
}
107
+ return createInternalError (originalException , env );
101
108
}
102
109
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 ();
105
112
if (logger .isErrorEnabled ()) {
106
113
logger .error ("Unresolved " + ex .getClass ().getSimpleName () + " for executionId " + executionId , ex );
107
114
}
108
115
return DataFetcherExceptionHandlerResult
109
- .newResult (GraphqlErrorBuilder .newError (environment )
116
+ .newResult (GraphqlErrorBuilder .newError (env )
110
117
.errorType (ErrorType .INTERNAL_ERROR )
111
118
.message (ErrorType .INTERNAL_ERROR + " for " + executionId )
112
119
.build ())
0 commit comments