Skip to content

Support GraphQLErrorBuilder as controller method argument #1200

Closed
@bclozel

Description

@bclozel

Our @GraphQlExceptionHandler example in the reference documentation shows the following:

@GraphQlExceptionHandler
public GraphQLError handle(BindException ex) {
	return GraphQLError.newError().errorType(ErrorType.BAD_REQUEST).message("...").build();
}

Doing so would return the error in the error map, but would miss critical information like "path" and "location".
You can get a better result with:

@GraphQlExceptionHandler
public GraphQLError handle(DataFetchingEnvironment environment, IllegalStateException ex) {
	return GraphqlErrorBuilder.newError(environment).errorType(ErrorType.BAD_REQUEST).message("...").build();
}

We should consider whether we should document this approach, or make available a GraphqlErrorBuilder parameter for error handlers with location/path information available from the environment.

Metadata

Metadata

Assignees

Labels

in: dataIssues related to working with datatype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions