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

Is there a way to parse S3 error response? #95

Open
pvgoran opened this issue Nov 7, 2023 · 0 comments
Open

Is there a way to parse S3 error response? #95

pvgoran opened this issue Nov 7, 2023 · 0 comments

Comments

@pvgoran
Copy link

pvgoran commented Nov 7, 2023

I'm experimenting with the library, and I get error responses from Amazon S3 in certain circumstances. The error response text is like this:

<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>PermanentRedirect</Code><Message>The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.</Message><Endpoint>s3.amazonaws.com</Endpoint><Bucket>...</Bucket><RequestId>...</RequestId><HostId>...</HostId></Error>

Now, I'm using examples/list_objects.rs as a basis for my code. The response status here is 301, so error_for_status() doesn't catch it, and the subsequent ListObjectsV2::parse_response() call on the response text produces a non-helpful error Custom("missing field `MaxKeys`").

Apparently I need to do more error handling: maybe make sure that the error code is always from the 2xx range, or "catch" parse errors and try to interpret the response as a error response. In any case, I need some way to parse the error response XML like the one I cited above. Is there any facility in rusty-s3 that would help me with it? I couldn't find any.

I think the library should have a error response type like ErrorResponse and a function to parse it, like parse_error_response. Maybe request objects should also have methods like parse_response_or_error that would automatically recognize, parse and return error responses.

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

No branches or pull requests

1 participant