@@ -43,6 +43,24 @@ public abstract class ExecutionStrategy {
4343
4444 public abstract ExecutionResult execute (ExecutionContext executionContext , ExecutionParameters parameters ) throws NonNullableFieldWasNullException ;
4545
46+ /**
47+ * Handle exceptions which occur during data fetching. By default, add all exceptions to the execution context's
48+ * error's. Subclasses may specify custom handling, e.g. of different behavior with different exception types (e.g.
49+ * re-throwing certain exceptions).
50+ * @param executionContext
51+ * @param fieldDef
52+ * @param argumentValues
53+ * @param e
54+ */
55+ protected void handleDataFetchingException (
56+ ExecutionContext executionContext ,
57+ GraphQLFieldDefinition fieldDef ,
58+ Map <String , Object > argumentValues ,
59+ Exception e ) {
60+ executionContext .addError (new ExceptionWhileDataFetching (e ));
61+ }
62+
63+
4664 protected ExecutionResult resolveField (ExecutionContext executionContext , ExecutionParameters parameters , List <Field > fields ) {
4765 GraphQLObjectType type = parameters .typeInfo ().castType (GraphQLObjectType .class );
4866 GraphQLFieldDefinition fieldDef = getFieldDef (executionContext .getGraphQLSchema (), type , fields .get (0 ));
@@ -70,8 +88,7 @@ protected ExecutionResult resolveField(ExecutionContext executionContext, Execut
7088 fetchCtx .onEnd (resolvedValue );
7189 } catch (Exception e ) {
7290 log .warn ("Exception while fetching data" , e );
73- executionContext .addError (new ExceptionWhileDataFetching (e ));
74-
91+ handleDataFetchingException (executionContext , fieldDef , argumentValues , e );
7592 fetchCtx .onEnd (e );
7693 }
7794
0 commit comments