Closed nadworny closed 1 year ago
I think the problem is that in your onException
handler you are doing:
.marshal().json();
Since the JSON RestBindingMode
is enabled, you don't need to do the marshalling step manually. It will result in Camel attempting to marshal an already marshalled body. Hence the 500 response.
Thanks for the suggestion @jamesnetherton . Unfortunately after applying it, nothing changed. Probably I forgot to mention but once the GeneratedRoute
is within the same configure as the onException
, everything works as expected.
That is expected as the 2 route builders are not sharing onException.
In Camel 3.12 onwards you can use route configurations to share error handling to all route builder classes https://camel.apache.org/manual/route-configuration.html
Description
I'm using an Camel REST DSL generator for my service. The generated class looks the following:
Now, I would like to handle the exception thrown by this endpoint when I send an invalid JSON request.
Expected behaviour
The exception processor is catching it and returning a custom error response.
Actual behaviour
A
500
is returned without going through the processor with the following stacktrace. Maybe that's a generic camel andRouteBuilder
problem that I can't catch exceptions that are created in a different class like the one which is generated?How to reproduce
Add the above GeneratedRoute to the rest example project
Add this ErrorResponse (or any pojo) which is generated also from the OpenAPI to the example project: https://gist.github.com/nadworny/4f391b2eeab28e94b3b297c1dd174d8c
Add this class to the Routes.java
Add the following code to the
configure()
method in Routes.javaSend an invalid request:
Environment
openjdk version "11.0.11" 2021-04-20 macos 11.6 (20G165) https://github.com/apache/camel-quarkus-examples version: b1352cd4c0d2a1b7b17ba73c3aca410f516d42f3