Skip to content

Commit ffbc9d4

Browse files
committed
- Changed pydggsapi to start with empty collections table in TinyDB
instead of crashed with exception. - If no collections are defined, it returns 404 error code with msg "there are no collections for querying"
1 parent 1516150 commit ffbc9d4

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

pydggsapi/dependencies/api/dggrs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def get_dggrs_descriptions() -> Dict[str, DggrsDescription]:
7171
logger.error(f"{__name__} {e}")
7272
raise Exception(f"{__name__} {e}")
7373
if (len(collections.keys()) == 0):
74-
logger.error(f"{__name__} no collections found")
75-
raise Exception(f"{__name__} no collections found")
74+
logger.warning(f"{__name__} no collections found")
75+
# raise Exception(f"{__name__} no collections found")
7676
dggrs_indexes = db.table('dggrs').all()
7777
if (len(dggrs_indexes) == 0):
7878
logger.error(f"{__name__} no dggrs defined.")

pydggsapi/routers/dggs_api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ async def collection_dggrs_description(
496496
collections: Annotated[Dict[str, Collection], Depends(_get_collection)],
497497
dggrs_provider=Depends(_get_dggrs_provider)
498498
) -> Union[DggrsDescription, Response]:
499+
# the collections should hold all collections defined or the colllection specified by the path variable
499500
dggrs_description = dggrs.model_copy(deep=True)
500501
current_url = str(req.url)
501502
col_id = getattr(dggrs_req, "collectionId", None)
@@ -541,6 +542,9 @@ async def collection_dggrs_zone_info(
541542
collections: Dict[str, Collection] = Depends(_get_collection),
542543
collection_provider: Dict[str, AbstractCollectionProvider] = Depends(_get_collection_provider),
543544
) -> Union[ZoneInfoResponse, Response]:
545+
# the collections should hold all collections defined or the colllection specified by the path variable
546+
if (len(collections.keys()) == 0):
547+
raise HTTPException(status_code=404, detail=f"f'{__name__} query zones info, there are no collections for querying")
544548
try:
545549
info = query_zone_info(zoneinfoReq, req.url, dggrs_description, dggrs_provider, collections, collection_provider)
546550
except ValueError as e:
@@ -591,6 +595,9 @@ async def collection_list_dggrs_zones(
591595
collection_provider: Annotated[Dict[str, AbstractCollectionProvider], Depends(_get_collection_provider)],
592596
) -> Union[ZonesResponse, ZonesGeoJson, Response]:
593597

598+
# the collections should hold all collections defined or the colllection specified by the path variable
599+
if (len(collections.keys()) == 0):
600+
raise HTTPException(status_code=404, detail=f"f'{__name__} query zones list, there are no collections for querying")
594601
returntype = _get_return_type(req, zone_query_support_returntype, zone_query_support_formats, 'application/json')
595602
returngeometry = zonesReq.geometry if (zonesReq.geometry is not None) else 'zone-region'
596603
zone_level = zonesReq.zone_level
@@ -692,6 +699,10 @@ async def collection_dggrs_zones_data(
692699
collections: Dict[str, Collection] = Depends(_get_collection),
693700
collection_provider: Dict[str, CollectionProvider] = Depends(_get_collection_provider),
694701
) -> ZonesDataDggsJsonResponse | FileResponse | Response:
702+
703+
# the collections should hold all collections defined or the colllection specified by the path variable
704+
if (len(collections.keys()) == 0):
705+
raise HTTPException(status_code=404, detail=f"f'{__name__} query zones data, there are no collections for querying")
695706
returntype = _get_return_type(req, zone_data_support_returntype, zone_data_support_formats, 'application/json')
696707
zoneId = zonedataReq.zoneId
697708
depth = zonedataQuery.zone_depth if (zonedataQuery.zone_depth is not None) else [dggrs_description.defaultDepth]

0 commit comments

Comments
 (0)