GithubHelp home page GithubHelp logo

Any `CustomErrorException`s thrown within custom code are automatically converted to `WebApplicationException` which discards all error objects about elide HOT 10 CLOSED

lewimuchiri avatar lewimuchiri commented on May 27, 2024
Any `CustomErrorException`s thrown within custom code are automatically converted to `WebApplicationException` which discards all error objects

from elide.

Comments (10)

aklish avatar aklish commented on May 27, 2024 1

We could probably find a way to expose that so you can customize the errors. We currently have a bean GraphQLConfiguration - but it is not that useful for something like this.

from elide.

aklish avatar aklish commented on May 27, 2024 1

from elide.

lewimuchiri avatar lewimuchiri commented on May 27, 2024

Just followed up and seen that the code that's causing this to happen is this one:
image

It's inside com.yahoo.elide.graphql.QueryRunner. It's throwing a new exception of type WebApplicationException which is causing it to lose all error objects in the original CustomErrorException.

from elide.

aklish avatar aklish commented on May 27, 2024

I see the first issue with Jersey, but not the second when I throw a CustomErrorException from a lifecycle hook. My custom error hits the error mapper and it includes all the error objects. Are you sure your lifecycle hook is triggering the exception (and not some other error)?

HTTP/1.1 200 OK
Date: Sun, 05 Mar 2023 01:27:18 GMT
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-XSS-Protection: 0
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: SAMEORIGIN
Content-Type: application/json
Content-Length: 47

{
    "errors": [
        {
            "message": "Custom Error Message"
        }
    ]
}

from elide.

aklish avatar aklish commented on May 27, 2024

Ok - I see the second issue now too for PREFLUSH and PRESECURITY hooks.

from elide.

aklish avatar aklish commented on May 27, 2024

So it looks like graphql-java swallows the exception:
Screen Shot 2023-03-05 at 3 07 39 PM

The exception is there, but there is no method on GraphQLError to get at it. In short, we can fix the first problem (the jersey issue), but I don't know of a solution to fix the 2nd without a corresponding patch to graphql-java.

from elide.

lewimuchiri avatar lewimuchiri commented on May 27, 2024

Yes, correct. I'm throwing my exception in a PRESECURITY hook.
For the 'ErrorObjects getting lost' problem, I suppose we can resolve this by defining a custom exception that implements GraphQLError. We can then add our extra errors to the extensions field (which is a map) in the Graphql error

from elide.

lewimuchiri avatar lewimuchiri commented on May 27, 2024

Again, using Elide, there's no way of overriding Graphql's DataFetcherExceptionHandler so that you can throw your own custom exceptions as you'd like. This is because we have to do something like this:

@Bean
public GraphQL graphQL(GraphQLSchema schema) {
    return GraphQL.newGraphQL(schema)
            .queryExecutionStrategy(new AsyncExecutionStrategy(new CustomDataFetcherExceptionHandler()))
            .mutationExecutionStrategy(new AsyncSerialExecutionStrategy(new CustomDataFetcherExceptionHandler()))
            .build();
}

which gives the error No beans of GraphQLSchema type found

from elide.

lewimuchiri avatar lewimuchiri commented on May 27, 2024

When will fix this get to Elide version 7? I'm still using version 7.0.0-pr2 (due to Spring Boot 3/Java 17 support). Version 7.0.0-pr2 is the only one that's available on Maven Central

from elide.

lewimuchiri avatar lewimuchiri commented on May 27, 2024

Thanks. Good stuff

from elide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.