Skip to content

Commit fc7ecc1

Browse files
committed
fix: 400 error blow ups when reponse not json
1 parent 6e19a47 commit fc7ecc1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/storage/src/storage3/_async/file_api.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,17 @@ async def _request(
5353
)
5454
response.raise_for_status()
5555
except HTTPStatusError as exc:
56-
resp = exc.response.json()
57-
raise StorageApiError(resp["message"], resp["error"], resp["statusCode"])
56+
try:
57+
# try parsing JSON safely
58+
resp = exc.response.json()
59+
except Exception:
60+
resp = {}
61+
62+
message = resp.get("message") or exc.response.text or "Unknown error"
63+
error = resp.get("error") or "UnknownError"
64+
status_code = resp.get("statusCode") or exc.response.status_code
65+
66+
raise StorageApiError(message, error, status_code)
5867

5968
# close the resource before returning the response
6069
if files and "file" in files and isinstance(files["file"][1], BufferedReader):

0 commit comments

Comments
 (0)