You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If my handler throws an error, then DataFetcherHandlerMethod (line 239) returns Mono.error(..), and then AnnotatedControllerExceptionResolver (line 241) tries to convert it to Mono again, which gives ClassCastException
Line 446 evaluates to false because it is instance of Mono and it tried to cast it to Collection<GraphQLError> and then fails.
And finally, I don't even get to see my actual error that got thrown in my exception handler in the logs, all I can see are these:
42:57.187 WARN --- [xec-7] a.s.AnnotatedControllerExceptionResolver: Failure while handling exception with *handler signature*
java.lang.ClassCastException...
42:57.189 WARN --- [xec-7] a.s.AnnotatedControllerExceptionResolver: Failure while handling exception with *handler signature*
java.lang.ClassCastException... --- why print the same log AGAIN?
42:57.190 WARN --- [xec-7] s.g.e.ExceptionResolversExceptionHandler: Failure while resolving *resolver signature*
jakarta.validation.ConstraintViolationException... ---- error that got thrown in the code and that I was trying to handle
The text was updated successfully, but these errors were encountered:
Thanks for the analysis but you are one step ahead of us. Can you show a minimal error handler code snippet that would trigger this so we can have a look?
rstoyanchev
changed the title
Error thrown in custom handler fails
Error thrown from @GraphQlExceptionHandler method results in ClassCastException
Jan 30, 2025
Uh oh!
There was an error while loading. Please reload this page.
If my handler throws an error, then
DataFetcherHandlerMethod
(line 239) returnsMono.error(..)
, and thenAnnotatedControllerExceptionResolver
(line 241) tries to convert it toMono
again, which givesClassCastException
spring-graphql/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerExceptionResolver.java
Lines 239 to 241 in 381c9f3
Specifically, in my case I see I threw an error from my handler
@GraphQlExceptionHandler fun handle(...): List<GraphQLError> {...}
that ended up here:After that, the
Mono.error
with my exception is attempted to be cast to the return type of my handler here:spring-graphql/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerExceptionResolver.java
Lines 444 to 449 in 381c9f3
Line 446 evaluates to
false
because it is instance ofMono
and it tried to cast it toCollection<GraphQLError>
and then fails.And finally, I don't even get to see my actual error that got thrown in my exception handler in the logs, all I can see are these:
The text was updated successfully, but these errors were encountered: