Search in sources :

Example 1 with ErrorClassification

use of graphql.ErrorClassification in project molgenis-emx2 by molgenis.

the class GraphqlCustomExceptionHandler method onException.

@Override
public DataFetcherExceptionHandlerResult onException(DataFetcherExceptionHandlerParameters handlerParameters) {
    final Throwable exception = handlerParameters.getException();
    final SourceLocation sourceLocation = handlerParameters.getSourceLocation();
    final ResultPath path = handlerParameters.getPath();
    GraphQLError error = new ExceptionWhileDataFetching(path, exception, sourceLocation);
    final ErrorClassification errorType = error.getErrorType();
    if (exception instanceof MolgenisException) {
        error = new GraphQLError() {

            @Override
            public String getMessage() {
                return exception.toString();
            }

            @Override
            public List<SourceLocation> getLocations() {
                return List.of(sourceLocation);
            }

            @Override
            public ErrorClassification getErrorType() {
                return errorType;
            }
        };
    }
    return DataFetcherExceptionHandlerResult.newResult().error(error).build();
}
Also used : SourceLocation(graphql.language.SourceLocation) ErrorClassification(graphql.ErrorClassification) ResultPath(graphql.execution.ResultPath) MolgenisException(org.molgenis.emx2.MolgenisException) GraphQLError(graphql.GraphQLError) ExceptionWhileDataFetching(graphql.ExceptionWhileDataFetching) List(java.util.List)

Example 2 with ErrorClassification

use of graphql.ErrorClassification in project graphql-java-extended-validation by graphql-java.

the class ResourceBundleMessageInterpolator method interpolate.

@Override
public GraphQLError interpolate(String messageTemplate, Map<String, Object> messageParams, ValidationEnvironment validationEnvironment) {
    ErrorClassification errorClassification = buildErrorClassification(messageTemplate, messageParams, validationEnvironment);
    String message = interpolateMessageImpl(messageTemplate, messageParams, validationEnvironment);
    GraphqlErrorBuilder errorBuilder = GraphqlErrorBuilder.newError().message(message).errorType(errorClassification).path(validationEnvironment.getExecutionPath());
    if (validationEnvironment.getLocation() != null) {
        errorBuilder.location(validationEnvironment.getLocation());
    }
    return errorBuilder.build();
}
Also used : ErrorClassification(graphql.ErrorClassification) GraphqlErrorBuilder(graphql.GraphqlErrorBuilder)

Aggregations

ErrorClassification (graphql.ErrorClassification)2 ExceptionWhileDataFetching (graphql.ExceptionWhileDataFetching)1 GraphQLError (graphql.GraphQLError)1 GraphqlErrorBuilder (graphql.GraphqlErrorBuilder)1 ResultPath (graphql.execution.ResultPath)1 SourceLocation (graphql.language.SourceLocation)1 List (java.util.List)1 MolgenisException (org.molgenis.emx2.MolgenisException)1