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();
}
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();
}
Aggregations