File tree Expand file tree Collapse file tree 3 files changed +53
-1
lines changed
main/java/graphql/servlet
test/groovy/graphql/servlet Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ protected List<GraphQLError> filterGraphQLErrors(List<GraphQLError> errors) {
4444 }
4545
4646 protected boolean isClientError (GraphQLError error ) {
47- return !(error instanceof ExceptionWhileDataFetching || error instanceof Throwable );
47+ if (error instanceof ExceptionWhileDataFetching ) {
48+ return ((ExceptionWhileDataFetching ) error ).getException () instanceof GraphQLError ;
49+ }
50+ return !(error instanceof Throwable );
4851 }
4952}
Original file line number Diff line number Diff line change @@ -641,6 +641,23 @@ class GraphQLServletSpec extends Specification {
641641 errors. first(). message. startsWith(" Internal Server Error(s)" )
642642 }
643643
644+ def " errors that also implement GraphQLError thrown while data fetching are passed to caller" () {
645+ setup :
646+ servlet = createServlet({ throw new TestGraphQLErrorException (" This is a test message" ) })
647+ request. addParameter(' query' , ' query { echo(arg:"test") }' )
648+
649+ when :
650+ servlet. doGet(request, response)
651+
652+ then :
653+ response. getStatus() == STATUS_OK
654+ response. getContentType() == CONTENT_TYPE_JSON_UTF8
655+ def errors = getResponseContent(). errors
656+ errors. size() == 1
657+ errors. first(). extensions. foo == " bar"
658+ errors. first(). message. startsWith(" Exception while fetching data (/echo) : This is a test message" )
659+ }
660+
644661 def " batched errors while data fetching are masked in the response" () {
645662 setup :
646663 servlet = createServlet({ throw new TestException () })
Original file line number Diff line number Diff line change 1+ package graphql.servlet
2+
3+ import graphql.ErrorType
4+ import graphql.GraphQLError
5+ import graphql.language.SourceLocation
6+
7+ /**
8+ * @author Andrew Potter
9+ */
10+ class TestGraphQLErrorException extends RuntimeException implements GraphQLError {
11+
12+ public TestGraphQLErrorException (String message ) {
13+ super (message);
14+ }
15+
16+ @Override
17+ public Map<String , Object > getExtensions () {
18+ Map<String , Object > customAttributes = new LinkedHashMap<> ();
19+ customAttributes. put(" foo" , " bar" );
20+ return customAttributes;
21+ }
22+
23+ @Override
24+ List<SourceLocation > getLocations () {
25+ return null
26+ }
27+
28+ @Override
29+ ErrorType getErrorType () {
30+ return ErrorType.ValidationError ;
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments