fix: check HTTP response status before parsing JSON body

upload_image() calls r.json() before checking r.ok. If the server
returns an error response (401, 500, etc) with a non-JSON body,
this raises a confusing JSONDecodeError instead of the intended
'Unable to get signed urls' error message.

Move the r.ok check before the r.json() call.
This commit is contained in:
ryzendigo 2026-03-16 14:47:53 +08:00
parent 5a214eb0d1
commit ab332c0395

View File

@ -105,9 +105,10 @@ class PlusApi:
def upload_image(self, image: ndarray, camera: str) -> str:
r = self._get("image/signed_urls")
presigned_urls = r.json()
if not r.ok:
raise Exception("Unable to get signed urls")
presigned_urls = r.json()
# resize and submit original
files = {"file": get_jpg_bytes(image, 1920, 85)}