fix(storage): raise StorageApiError when a bucket error body is unrecognized - #1574
Open
tushardev-365 wants to merge 1 commit into
Open
fix(storage): raise StorageApiError when a bucket error body is unrecognized#1574tushardev-365 wants to merge 1 commit into
tushardev-365 wants to merge 1 commit into
Conversation
…ognized
StorageBucketAPI._request indexed the parsed error body directly:
resp = exc.response.json()
raise StorageApiError(resp["message"], resp["error"], resp["statusCode"])
A storage error whose JSON body is missing any of those keys therefore
surfaced as a bare KeyError, and a body that is not JSON at all (an HTML
page from a proxy or gateway, say) surfaced as a JSONDecodeError. Either
way the caller lost the real status and body and got an opaque exception
instead of StorageApiError, on the path where the message matters most.
Wrap the lookup and fall back to StorageApiError carrying the raw
response text, mirroring the shape file_api._request already uses and the
ValidationError fallback in request.py for vector buckets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
StorageBucketAPI._requestindexed the parsed error body directly:So a storage error whose JSON body is missing any of
message/error/statusCodecame back as a bareKeyError, and a body that isn't JSON at all (an HTML page from a proxy or gateway) came back as aJSONDecodeError. Either way the caller lost the real status and body and got an opaque exception instead ofStorageApiError— on the one path where the message matters most. This affects every bucket operation:list_buckets,get_bucket,create_bucket,update_bucket,empty_bucket,delete_bucket.Fix
Wrap the lookup and fall back to
StorageApiErrorcarrying the raw response text, mirroring the shapefile_api._requestalready uses and theValidationErrorfallbackrequest.pyuses for vector buckets.Tests
Two new cases per flavour (async + sync), asserting
StorageApiErrorrather than the leaked exception:Reverting only the source change makes all four fail with the raw
KeyError/JSONDecodeError; with the fix the bucket suite is 28 passed.Note
#1563 reports this same class of bug in
file_api._request(its recovery path reaches forresp.texton a dict), and there are already PRs open for that file. This PR is the bucket API only, which is a separate_requestwith no recovery path at all — so the two don't overlap._syncis generated, so the change was made in_asyncand regenerated withmake build-sync; only the bucket files are included here.