mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-07-24 21:41:04 +02:00
fix: degrade list_collections when folders are unavailable (403/404)
GET /folders/ is gated by the folder plan server-side, so on plans without folder support list_collections raised CloudAPIError while every sibling folder method (create_collection, get_or_create_collection, delete_collection) degrades gracefully. Catch _FOLDER_UNAVAILABLE, emit the one-time upgrade warning, and return []; transient errors still propagate.
This commit is contained in:
parent
f995e6441e
commit
29971049ae
2 changed files with 29 additions and 1 deletions
|
|
@ -173,7 +173,13 @@ class CloudBackend:
|
|||
return None
|
||||
|
||||
def list_collections(self) -> list[str]:
|
||||
data = self._request("GET", "/folders/")
|
||||
try:
|
||||
data = self._request("GET", "/folders/")
|
||||
except CloudAPIError as e:
|
||||
if e.status_code in self._FOLDER_UNAVAILABLE:
|
||||
self._warn_folder_upgrade()
|
||||
return []
|
||||
raise
|
||||
return [f["name"] for f in data.get("folders", []) or []]
|
||||
|
||||
def delete_collection(self, name: str) -> None:
|
||||
|
|
|
|||
|
|
@ -127,6 +127,28 @@ def test_folder_transient_error_propagates_and_is_not_cached(monkeypatch):
|
|||
assert "col" not in backend._folder_id_cache
|
||||
|
||||
|
||||
def test_list_collections_degrades_when_folders_unavailable(monkeypatch):
|
||||
backend = CloudBackend(api_key="pi-test")
|
||||
|
||||
def fake_request(method, path, **kwargs):
|
||||
raise CloudAPIError("Cloud API error 403: upgrade", status_code=403)
|
||||
|
||||
monkeypatch.setattr(backend, "_request", fake_request)
|
||||
with pytest.warns(UserWarning, match="not available on this plan"):
|
||||
assert backend.list_collections() == []
|
||||
|
||||
|
||||
def test_list_collections_propagates_transient_error(monkeypatch):
|
||||
backend = CloudBackend(api_key="pi-test")
|
||||
|
||||
def fake_request(method, path, **kwargs):
|
||||
raise CloudAPIError("Cloud API error 503: unavailable", status_code=503)
|
||||
|
||||
monkeypatch.setattr(backend, "_request", fake_request)
|
||||
with pytest.raises(CloudAPIError):
|
||||
backend.list_collections()
|
||||
|
||||
|
||||
# ── doc endpoints: 404 maps to DocumentNotFoundError (local parity) ──────────
|
||||
|
||||
def test_doc_404_maps_to_document_not_found(monkeypatch):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue