micronaut-core icon indicating copy to clipboard operation
micronaut-core copied to clipboard

Make empty body configurable behaviour

Open CezaryBD opened this issue 1 year ago • 8 comments

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

https://github.com/CezaryBD/micronaut-reactor-mono-void-bug-01/blob/main/src/test/java/com/example/DemoTest.java

Version

4.3.3

CezaryBD avatar May 08 '24 09:05 CezaryBD

@CezaryBD for an empty body I think a 204 response would be more idiomatic.

sdelamo avatar May 08 '24 13:05 sdelamo

@sdelamo depends on the approach, but generally, yes - 204 would be a much better solution.

CezaryBD avatar May 08 '24 13:05 CezaryBD

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.

yawkat avatar May 13 '24 17:05 yawkat

I think if the status code > 200, then no exception should be fired, cause this can be an expected behaviour.

CezaryBD avatar May 14 '24 06:05 CezaryBD

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

yawkat avatar May 14 '24 08:05 yawkat

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

CezaryBD avatar May 14 '24 13:05 CezaryBD

ah, you want an empty mono? that would indeed be a reasonable value. i was thinking of the blocking case.

yawkat avatar May 15 '24 09:05 yawkat

empty Mono should be passed just fine

CezaryBD avatar May 15 '24 09:05 CezaryBD