akka-http icon indicating copy to clipboard operation
akka-http copied to clipboard

Make `toStrictEntity` fail with bad request in case of entity errors

Open mpdn opened this issue 2 years ago • 2 comments

Fixes https://github.com/akka/akka-http/issues/4134

Unsure what exactly to add to the docstring, if anything. Could be something like Fails the route with an [IllegalRequestException] if the request framing is invalid - thoughts?

This rethrows EntityStreamException as IllegalRequestException. This matches more things than the above issue - eg. situations such as exceeding the max entity size. Turns out, exceeding the max entity size also resulted in an internal server error previously and due to this change now results in a bad request - it really ought to be a 413 entity too large, but I can't really distinguish these errors as they currently use the same underlying exception types. But at least 400 Bad Request is better than 500 internal error.

mpdn avatar Jun 15 '22 09:06 mpdn

We actually do have an EntityStreamSizeException - I wonder why we don't throw that one in toStrict instead of a generic EntityStreamException.

Yeah, I was wondering about that as well. EntityStreamSizeException does not extend EntityStreamException though, and does not have an ErrorInfo so it's fairly different to the exception it currently throws.

mpdn avatar Jun 15 '22 12:06 mpdn

We actually do have an EntityStreamSizeException - I wonder why we don't throw that one in toStrict instead of a generic EntityStreamException.

Yeah, I was wondering about that as well. EntityStreamSizeException does not extend EntityStreamException though, and does not have an ErrorInfo so it's fairly different to the exception it currently throws.

Ah right - so it's useful to use EntityStreamException to get the split between public and private info, and EntityStreamSizeException won't get that until we finish https://github.com/akka/akka-http/pull/3439 . :+1:

raboof avatar Jun 17 '22 08:06 raboof