Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

No location and path in error response #453

Closed
tfij opened this issue Sep 7, 2020 · 1 comment
Closed

No location and path in error response #453

tfij opened this issue Sep 7, 2020 · 1 comment
Labels
Milestone

Comments

@tfij
Copy link

tfij commented Sep 7, 2020

Implementation of graphql.execution.SimpleDataFetcherExceptionHandler puts location and path to error object.
However, graphql.kickstart.spring.error.GraphQLErrorFromExceptionHandler clears that information, and error contains only a message.

From GraphQLErrorFromExceptionHandler:

private Collection<GraphQLError> transform(GraphQLError error) {
    return extractException(error).map(this::transform)
        .orElse(singletonList(new GenericGraphQLError(error.getMessage())));
  }

This code extract exception and build new GraphQLError object without location and path.

Alternatively, ther is no way to get location and path in handling exception like this

    @ExceptionHandler(Exception.class)
    GraphQLError handleGenericException(Exception ex) {
        return new ThrowableGraphQLError(ex, ex.getMessage());
    }
@tfij
Copy link
Author

tfij commented Oct 6, 2020

I just ran 7.2.0-SNAPSHOT on my own and it works exactly as it should!
Example code:

    @ExceptionHandler(Exception.class)
    GraphQLError handleGenericException(Exception ex, ErrorContext errorContext) {
        meterRegistry.counter("api.graphql.error", "expected", "false", "class", ex.getClass().getSimpleName()).increment();
        return GraphqlErrorBuilder.newError()
                .message(ex.getMessage())
                .locations(errorContext.getLocations())
                .path(errorContext.getPath())
                .build();
    }

ErrorContext could contain additional information about the original error ʻextensions`.
I've just create a PR with it - #465
Meanwhile, I am waiting for the release of version 7.2.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants