Skip to content

Commit 1262e89

Browse files
committed
fix item collection, single item error messages
1 parent d3e6591 commit 1262e89

File tree

1 file changed

+5
-4
lines changed
  • stac_fastapi/elasticsearch/stac_fastapi/elasticsearch

1 file changed

+5
-4
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,16 @@ def item_collection(
102102
"""Read an item collection from the database."""
103103
links = []
104104
base_url = str(kwargs["request"].base_url)
105-
106105
search = Search(using=self.client, index="stac_items")
107106

108107
collection_filter = Q(
109108
"bool", should=[Q("match_phrase", **{"collection": collection_id})]
110109
)
111110
search = search.query(collection_filter)
112-
113-
count = search.count()
111+
try:
112+
count = search.count()
113+
except elasticsearch.exceptions.NotFoundError:
114+
raise NotFoundError(f"No items exist for this collection yet")
114115
# search = search.sort({"id.keyword" : {"order" : "asc"}})
115116
search = search.query()[0:limit]
116117
collection_children = search.execute().to_dict()
@@ -141,7 +142,7 @@ def get_item(self, item_id: str, collection_id: str, **kwargs) -> Item:
141142
try:
142143
item = self.client.get(index="stac_items", id=item_id)
143144
except elasticsearch.exceptions.NotFoundError:
144-
raise NotFoundError
145+
raise NotFoundError(f"Item {item_id} does not exist in Collection {collection_id}")
145146
return self.item_serializer.db_to_stac(item["_source"], base_url)
146147

147148
def _return_date(self, datetime):

0 commit comments

Comments
 (0)