Spaces:
Running on Zero
Running on Zero
fix: map Supabase missing objects to not found
Browse files- backend/app/storage.py +9 -1
backend/app/storage.py
CHANGED
|
@@ -111,7 +111,15 @@ def download_bytes(key, use_cache=True):
|
|
| 111 |
if use_cache and cp.exists():
|
| 112 |
return cp.read_bytes()
|
| 113 |
r = requests.get(public_url(key), timeout=_TIMEOUT)
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
raise FileNotFoundError(key)
|
| 116 |
if r.status_code != 200:
|
| 117 |
raise StorageError(f"download {key} failed: {r.status_code}")
|
|
|
|
| 111 |
if use_cache and cp.exists():
|
| 112 |
return cp.read_bytes()
|
| 113 |
r = requests.get(public_url(key), timeout=_TIMEOUT)
|
| 114 |
+
missing = r.status_code == 404
|
| 115 |
+
if r.status_code == 400:
|
| 116 |
+
try:
|
| 117 |
+
payload = r.json()
|
| 118 |
+
missing = (str(payload.get("statusCode")) == "404"
|
| 119 |
+
or payload.get("error") == "not_found")
|
| 120 |
+
except ValueError:
|
| 121 |
+
pass
|
| 122 |
+
if missing:
|
| 123 |
raise FileNotFoundError(key)
|
| 124 |
if r.status_code != 200:
|
| 125 |
raise StorageError(f"download {key} failed: {r.status_code}")
|