Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ protected List<GraphQLError> filterGraphQLErrors(List<GraphQLError> errors) {
}

protected boolean isClientError(GraphQLError error) {
return !(error instanceof ExceptionWhileDataFetching || error instanceof Throwable);
if (error instanceof ExceptionWhileDataFetching) {
return ((ExceptionWhileDataFetching) error).getException() instanceof GraphQLError;
}
return !(error instanceof Throwable);
}
}
17 changes: 17 additions & 0 deletions src/test/groovy/graphql/servlet/GraphQLServletSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,23 @@ class GraphQLServletSpec extends Specification {
errors.first().message.startsWith("Internal Server Error(s)")
}

def "errors that also implement GraphQLError thrown while data fetching are passed to caller"() {
setup:
servlet = createServlet({ throw new TestGraphQLErrorException("This is a test message") })
request.addParameter('query', 'query { echo(arg:"test") }')

when:
servlet.doGet(request, response)

then:
response.getStatus() == STATUS_OK
response.getContentType() == CONTENT_TYPE_JSON_UTF8
def errors = getResponseContent().errors
errors.size() == 1
errors.first().extensions.foo == "bar"
errors.first().message.startsWith("Exception while fetching data (/echo) : This is a test message")
}

def "batched errors while data fetching are masked in the response"() {
setup:
servlet = createServlet({ throw new TestException() })
Expand Down
32 changes: 32 additions & 0 deletions src/test/groovy/graphql/servlet/TestGraphQLErrorException.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package graphql.servlet

import graphql.ErrorType
import graphql.GraphQLError
import graphql.language.SourceLocation

/**
* @author Andrew Potter
*/
class TestGraphQLErrorException extends RuntimeException implements GraphQLError {

public TestGraphQLErrorException(String message) {
super(message);
}

@Override
public Map<String, Object> getExtensions() {
Map<String, Object> customAttributes = new LinkedHashMap<>();
customAttributes.put("foo", "bar");
return customAttributes;
}

@Override
List<SourceLocation> getLocations() {
return null
}

@Override
ErrorType getErrorType() {
return ErrorType.ValidationError;
}
}