micronaut-core
micronaut-core copied to clipboard
Make empty body configurable behaviour
Expected Behavior
It should be configurable if fail or pass the response.
Actual Behaviour
https://github.com/micronaut-projects/micronaut-core/commit/ab5c4a244b25113d06378771bd43dfa7db7c29bc#diff-af18b3b8347409fdb81dedda7689f9d13c962d129830818e2dbd4c48770ddecdR151 Line #166. This change introduces a default behaviour that I would prefer to be configurable. An empty body on 200 OK status is not an error :)
Steps To Reproduce
No response
Environment Information
No response
Example Application
Version
4.3.3
@CezaryBD for an empty body I think a 204 response would be more idiomatic.
@sdelamo depends on the approach, but generally, yes - 204 would be a much better solution.
That change did not introduce empty behavior, it added an exception message for decoding failures.
What would you like to happen when the body is empty? We can't decode it as json.
I think if the status code > 200, then no exception should be fired, cause this can be an expected behaviour.
For status codes >=400 we already have exception-on-error-status.
For 2xx with empty body, we can't parse the body as json, so there is no sensible default to return. We must throw
Pardon my manners, example app was not included in the ticket description. Sorry for asking, but why do you need to throw? It seems to me, that I will need to create a little boilerplate every time I need to return an empty body, because micronaut-reactor cannot handle it. I see that Spring's WebFlux is doing the same. 204 with empty body is no error: https://datatracker.ietf.org/doc/html/rfc9110#name-204-no-content
ah, you want an empty mono? that would indeed be a reasonable value. i was thinking of the blocking case.
empty Mono should be passed just fine