Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle streaming exceptions as bad requests instead of internal errors #178

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thinaih
Copy link
Member

@thinaih thinaih commented Mar 11, 2025

Currently the proxy handles most streaming issues due to mismatch between declared content length and uploaded content length as INTERNAL_ERRORs, except for when it's a STANDARD or W3C_CHUNKED and uploaded > content length, then this is handled as UNAUTHORIZED.

This PR is suggesting handle all of the above as BAD_REQUEST.

@cla-bot cla-bot bot added the cla-signed label Mar 11, 2025
@thinaih thinaih force-pushed the handle-stream-errors-as-client-errors branch from 0eb1106 to d7b16a8 Compare March 12, 2025 16:20
@thinaih thinaih marked this pull request as ready for review March 12, 2025 16:39
@@ -61,7 +60,7 @@ public int read()

int i = delegate.read();
if (i < 0) {
throw new EOFException("Unexpected end of stream");
throw new AwsProxyStreamException("Unexpected end of stream");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an existing AWS SDK Exception we can throw?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is the SdkServiceException or its subclass AwsServiceException. However I didn't want to use them since I think it might be better to separate the exceptions thrown by the proxy stream classes and handle them differently. Creating this new exception makes it possible to do so without the risk of swallowing other exceptions that might need to be handled differently. wdyt?

Copy link
Member

@Randgalt Randgalt Mar 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe WebApplicationException is better. I'm generally against defining bespoke exceptions unless absolutely necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this class doesn't need to know that this should be handled as a 400 or something else, there is also an issue #73 that aims to separate internal exceptions from the http logic, and throwing a WebApplicationException here, will not take us closer to addressing that issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my opinion. I don't think we should be defining new exceptions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Jordan here, creating custom exception classes that don't have extra fields or functions makes the code more convoluted.
This class is part of the proxy's "private" core and is pretty close to networking code, so throwing a WebApplicationException makes sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants