Custom ExceptionMiddleware not catching exceptions #5510
-
Hi @michaelstaib, I'm new to HotChocolate and GraphQL, but I'm loving what your library can do. I have a basic requirement where I want to use FluentValidation, and if a ValidationException is thrown, then I use the error builder to transform those error details and throw a GraphQLException. Something like:
I was hoping it would then get caught by your ExceptionMiddleware and output accordingly. My program setup looks like:
However, my middleware always completes fine without any exceptions caught. Any idea what I'm doing wrong? Here is a silly example query to illustrate what I'm doing:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi All, does anyone have a solution for this? It would be nice to know what I'm doing wrong here. Thanks! |
Beta Was this translation helpful? Give feedback.
-
HI .... what I think is your middleware is being registered very late in request execution pipeline. You can try to use immediately after AddGraphQLServer like below ......or
|
Beta Was this translation helpful? Give feedback.
-
Resolver error are not propagated to the request middleware... The request pipeline represents a modular pipeline for the request level execution steps. The field middleware represents this for the GraphQL field. In your case you are throwing an exception in the resolver so you need to use a filed middleware. In any case, if you just want to catch and log resolver level errors / exception use the diagnostic events an override ResolverError. |
Beta Was this translation helpful? Give feedback.
Resolver error are not propagated to the request middleware...
The request pipeline represents a modular pipeline for the request level execution steps.
The field middleware represents this for the GraphQL field. In your case you are throwing an exception in the resolver so you need to use a filed middleware.
In any case, if you just want to catch and log resolver level errors / exception use the diagnostic events an override ResolverError.