如何在GraphQL Java中重写DataFetcherExceptionHandler?

如何在GraphQL Java中重写DataFetcherExceptionHandler?,java,graphql,graphql-java,Java,Graphql,Graphql Java,我正在使用以下启动程序进行Graphql集成 <dependency> <groupId>com.graphql-java-kickstart</groupId> <artifactId>graphql-spring-boot-starter</artifactId> <version>6.0.1</version> </dependency> com.graphql-ja

我正在使用以下启动程序进行Graphql集成

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

com.graphql-java-kickstart
graphql弹簧启动机
6.0.1
  • 我不知道如何用我自己的CustomExceptionHandler覆盖SimpleDataFetcherExceptionHandler。图书馆已经自动连接了很多东西。我是否需要为graphQl对象创建单独的配置?文档没有多大帮助

  • 我还尝试将@ControllerAdvice集成到我的Graphql java spring启动应用程序中,但其中的异常处理程序无法匹配错误。它们由GraphQl错误处理程序处理。错误如何在Graphql中传播


  • 我怎样才能改变这种行为?

    我有这个,它对我有效。非常常规的spring异常处理功能,但是没有
    @ControllerAdvice
    (顺便说一句,如果你不明白的话,请告诉我,但我认为即使没有kotlin知识,这也很清楚)

    import org.springframework.web.bind.annotation.ExceptionHandler
    导入com.oembedler.moon.graphql.boot.error.ThrowableGraphQLError
    内部类GraphQLExceptionHandler{
    @ExceptionHandler(AppException::类)
    fun HandleGenericeException(例如:AppException):ThrowableGraphQLError{
    返回ThrowableGraphQLError(ex)
    }
    @ExceptionHandler(异常::类)
    fun HandleGenericeException(例如:异常):ThrowableGraphQLError{
    返回ThrowableGraphQLError(TechnicalException())
    }
    }
    @配置
    内部开放类GraphQLConfiguration{
    @豆子
    打开有趣的graphQLExceptionHandler():graphQLExceptionHandler{
    返回GraphQLExceptionHandler()
    }
    }
    
    我有很多依赖项,如果它们在这里很重要:

    5.4.1
    1.4.0
    com.graphql-java-kickstart
    graphql弹簧启动机
    ${graphql.version}
    com.graphql-java-kickstart
    graphiql弹簧启动机
    ${graphql.version}
    com.graphql-java-kickstart
    旅行者弹簧启动机
    ${graphql.version}
    com.graphql-java-kickstart
    graphql java工具
    ${graphql.version}
    com.zhokhov.graphql
    graphql日期时间弹簧启动启动器
    ${graphql datetime spring boot starter.version}
    
    基本上,我希望将错误包装在响应实体中,并返回正确的响应代码。我在哪里可以处理这个问题?@Abhinav使用200以外的代码响应是违反graphql文档的