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

GraphQLErrorHandlerFactory does not find ExceptionHandlers #166

Closed
juriad opened this issue Nov 29, 2018 · 9 comments
Closed

GraphQLErrorHandlerFactory does not find ExceptionHandlers #166

juriad opened this issue Nov 29, 2018 · 9 comments
Labels

Comments

@juriad
Copy link

juriad commented Nov 29, 2018

  1. a method annotated with ExceptionHandler is not found if the bean is a CGLib proxy (e.g. Configuration) or if the method is defined in an ancestor

  2. a bean may not be found in context.getBean(className) as the bean can be registered in the application context with a name different from its fully qualified name - this leads to NoSuchBeanDefinitionException and application failure

I managed to overcome both issues with:

@Component("com.company.x360.ExceptionHandlers")
class ExceptionHandlers {

    @ExceptionHandler(Throwable::class)
    fun handleException(e: Throwable): GraphQLError {
@oliemansm oliemansm added the bug label Nov 30, 2018
@Guchelkaben
Copy link

Guchelkaben commented Dec 11, 2018

@juriad thanks for the solution but do i miss sth? my handleException got never called. I enabled the graphql servlet property in my application.yml ? UsernameNotFoundException works but if I get a CoercingParseValueException Exception then this method will never called.

@Component("XXX")
public class Test {

    @ExceptionHandler({Throwable.class, Exception.class, CoercingParseValueException.class, UsernameNotFoundException.class})
    GraphQLError handleException(Throwable e) {
        System.out.println("Hello");
        return new ThrowableGraphQLError(e);
    }
}

even create a custom GraphQLErrorHandler does not work.

@Component
public class CustomGraphQLErrorHandler implements GraphQLErrorHandler {

    @Override
    public boolean errorsPresent(List<GraphQLError> errors) {
        System.out.println("Hello World");
        return false;
    }

    @Override
    public List<GraphQLError> processErrors(List<GraphQLError> list) {
        System.out.println("Hello World2");
        return null;
    }
}

@oliemansm
Copy link
Member

@Guchelkaben The exception handler is intended for exceptions that occur during execution of queries/mutations, but after the actual parsing. So those "internal" GraphQL handling exceptions are not covered by these. Think that's the reason it does work with your UsernameNotFoundException, but it doesn't with the CoercingParseValueException.

@Guchelkaben
Copy link

@oliemansm thx for your reply. Do you know how I can cover the "internal" GraphQL handling? Because these error messages from the "internal" GraphQL are not very accurate. Therefore I want to override them and assign better messages.

Otherwise, our frontend must filter the returned string for explicit words, what kind of strange for me :D Instead I want to set a response code or sth else like bad request 400.

@oliemansm
Copy link
Member

@Guchelkaben To be able to do this we need to extend the GraphQLErrorFromExceptionHandler. GraphQL throws various types of GraphQLException (the "internal" GraphQL errors I was mentioning), one of which is the ExceptionWhileDataFetching. That exception contains a certain Throwable cause, and the @ExceptionHandler annotation is currently used to find methods handling that specific cause.

What we could do is to also include the GraphQLException and its subclasses such as CoercingParseValueException in the search.

@oliemansm
Copy link
Member

@Guchelkaben Could you try this again with 5.4.1-SNAPSHOT?

@Guchelkaben
Copy link

@Guchelkaben Could you try this again with 5.4.1-SNAPSHOT?

How can I integrate 5.4.1-SNAPSHOT into my project?

@oliemansm
Copy link
Member

Add the snapshot repository. See also https://www.graphql-java-kickstart.com/spring-boot/getting-started/

repositories {
    mavenCentral()
    maven { url "http://oss.jfrog.org/artifactory/oss-snapshot-local" }
}

@Guchelkaben
Copy link

Guchelkaben commented Dec 15, 2018

Add the snapshot repository. See also https://www.graphql-java-kickstart.com/spring-boot/getting-started/

repositories {
    mavenCentral()
    maven { url "http://oss.jfrog.org/artifactory/oss-snapshot-local" }
}

Thx, and then replace the version of graphql-spring-boot-starter to 5.4.1-SNAPSHOT? Because if I do that maven don't download anything 🗡

<dependency>
            <groupId>com.graphql-java-kickstart</groupId>
            <artifactId>graphql-spring-boot-starter</artifactId>
            <version>5.4.1-SNAPSHOT</version>
        </dependency>

Error: Could not find artifact com.graphql-java-kickstart:graphql-spring-boot-starter:jar:5.4.1-SNAPSHOT in oss-snapshot-local (http://oss.jfrog.org/artifactory/oss-snapshot-local) -> [Help 1]

And at jfrog, there is no dependency like this.

@oliemansm Did you upload it? Thanks for your effort!

@oliemansm
Copy link
Member

@Guchelkaben Apparently snapshots aren't configured properly for this project yet, thought it was sorry. I've released this in the meantime and it has already been confirmed to work now by other developers.

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

3 participants