Closed jacekgajek closed 2 years ago
You're supposed to throw the exception, not return it directly
Yes I know that. I have a global exception handler which returns a thrown exception, this is just a simplified example. It works great for most of exception and provides very useful info about internal error (the REST service is for internal use and it's OK to expose these details)
So you actually want the full Throwable serialized, including stack trace and such?
The exceptions from the micronaut framework do not generally support serialization. If they do, it's by accident. In my opinion we shouldn't either, since serializing throwables is generally a dangerous practice that could lead to information leaks (though it might not in your case).
Consider using micronaut-problem-json instead. It has support for serializing stack traces if configured to do so, and if the exception is a ThrowableProblem.
Indeed serializing exceptions directly can result in leaking information which could lead to security vulnerabilities so this is not a good idea.
Thanks for a fast response and explanation. Have a nice day :)
Expected Behavior
HttpClientResponseException serialized to JSON in response
Actual Behaviour
Response:
"Internal Server Error: Error encoding object [io.micronaut.http.client.exceptions.HttpClientResponseException: asd] to JSON: No serializer found for class io.netty.handler.codec.http.cookie.ServerCookieEncoder and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: io.micronaut.http.client.exceptions.HttpClientResponseException[\"response\"]->io.micronaut.http.netty.NettyMutableHttpResponse[\"serverCookieEncoder\"])",
Steps To Reproduce
Launch a GET request to an endpoint which returns a HttpClientResponseException, for example
Environment Information
Ubuntu 20.04.3 LTS openjdk-15.0.1
Example Application
No response
Version
3.2.0