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
@@ -60,9 +65,11 @@ class ExceptionResolversExceptionHandler implements DataFetcherExceptionHandler
60
65
61
66
@ Override
62
67
@ 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 ();
66
73
ContextSnapshot snapshot = ContextSnapshot .captureFrom (env .getGraphQlContext ());
67
74
try {
68
75
return Flux .fromIterable (this .resolvers )
@@ -80,34 +87,34 @@ public CompletableFuture<DataFetcherExceptionHandlerResult> handleException(Data
80
87
}
81
88
}
82
89
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
-
92
90
private Throwable unwrapException (DataFetcherExceptionHandlerParameters params ) {
93
91
Throwable ex = params .getException ();
94
92
return ((ex instanceof CompletionException ) ? ex .getCause () : ex );
95
93
}
96
94
97
95
private void logResolvedException (Throwable ex , DataFetcherExceptionHandlerResult result ) {
98
96
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 );
101
107
}
108
+ return createInternalError (originalException , env );
102
109
}
103
110
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 ();
106
113
if (logger .isErrorEnabled ()) {
107
114
logger .error ("Unresolved " + ex .getClass ().getSimpleName () + " for executionId " + executionId , ex );
108
115
}
109
116
return DataFetcherExceptionHandlerResult
110
- .newResult (GraphqlErrorBuilder .newError (environment )
117
+ .newResult (GraphqlErrorBuilder .newError (env )
111
118
.errorType (ErrorType .INTERNAL_ERROR )
112
119
.message (ErrorType .INTERNAL_ERROR + " for " + executionId )
113
120
.build ())
0 commit comments