tapir icon indicating copy to clipboard operation
tapir copied to clipboard

[BUG] Can no longer return 304 with empty string as body - get 500 internal server error

Open kschuetz opened this issue 1 year ago • 4 comments

Tapir version: 1.10.5

Scala version: 3.3.1

Describe the bug I have some endpoints in my application whose implementations sometimes return a 304 with an empty string as a body.

I have upgraded tapir recently (from 1.2.13 to 1.10.5), and as of this commit, those endpoints no longer work: https://github.com/softwaremill/tapir/commit/2380053aef58a633317adbc0e90902f608787b78

Whenever the endpoints attempt to return a 304, I get a 500 Internal Server Error instead.

It looks like the cause is this line: case (StatusCode.NoContent | StatusCode.NotModified, Some(_)) => monad.error(new IllegalStateException(s"Unexpected response body when status code == $statusCode"))

Is there any way to disable this check or get around it? I won't be able to change the API contract of my application.

kschuetz avatar Apr 23 '24 20:04 kschuetz

As a temporary workaround, I made my endpoints return 399 and added an interceptor at the top level to convert 399s to 304s.

kschuetz avatar Apr 23 '24 22:04 kschuetz

I think it's the same problem as #3682

Since this is problematic, let's simply remove this check.

adamw avatar Apr 24 '24 06:04 adamw

Appreciate the quick response!

kschuetz avatar Apr 24 '24 14:04 kschuetz

Still looking for somebody to create the PR, just in case :)

adamw avatar Apr 24 '24 14:04 adamw