Search in sources :

Example 1 with GraphqlErrorBuilder

use of graphql.GraphqlErrorBuilder 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)

Example 2 with GraphqlErrorBuilder

use of graphql.GraphqlErrorBuilder in project teamcity-rest by JetBrains.

the class ResolverExceptionHandler method onException.

@Override
public DataFetcherExceptionHandlerResult onException(DataFetcherExceptionHandlerParameters handlerParameters) {
    Throwable exception = handlerParameters.getException();
    SourceLocation sourceLocation = handlerParameters.getSourceLocation();
    ExecutionPath path = handlerParameters.getPath();
    GraphqlErrorBuilder builder = GraphqlErrorBuilder.newError().path(path).location(sourceLocation);
    if (exception.getMessage() != null) {
        builder.message(exception.getMessage());
    } else {
        builder.message(exception.getClass().getSimpleName());
    }
    if (exception instanceof AccessDeniedException) {
        GraphQLError error = builder.errorType(TeamCityGraphQLErrorType.ACCESS_DENIED).build();
        return DataFetcherExceptionHandlerResult.newResult().error(error).build();
    }
    if (exception instanceof NotFoundException) {
        GraphQLError error = builder.errorType(TeamCityGraphQLErrorType.NOT_FOUND).build();
        return DataFetcherExceptionHandlerResult.newResult().error(error).build();
    }
    LOG.warnAndDebugDetails("Exception occured while fetching data.", exception);
    GraphQLError error = builder.errorType(TeamCityGraphQLErrorType.SERVER_ERROR).build();
    return DataFetcherExceptionHandlerResult.newResult().error(error).build();
}
Also used : SourceLocation(graphql.language.SourceLocation) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) GraphQLError(graphql.GraphQLError) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) GraphqlErrorBuilder(graphql.GraphqlErrorBuilder) ExecutionPath(graphql.execution.ExecutionPath)

Aggregations

GraphqlErrorBuilder (graphql.GraphqlErrorBuilder)2 ErrorClassification (graphql.ErrorClassification)1 GraphQLError (graphql.GraphQLError)1 ExecutionPath (graphql.execution.ExecutionPath)1 SourceLocation (graphql.language.SourceLocation)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 AccessDeniedException (jetbrains.buildServer.serverSide.auth.AccessDeniedException)1