Skip to content

Commit 248576b

Browse files
authored
fix: don't error when search returns no body (#594)
1 parent d1a3626 commit 248576b

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/stac_api_validator/validations.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3199,23 +3199,26 @@ def validate_item_search_ids(
31993199
r_session=r_session,
32003200
)
32013201

3202-
items = body.get("features") # type: ignore
3203-
if items and len(items) >= 2:
3204-
_validate_search_ids_with_ids(
3205-
search_url, [items[0].get("id")], methods, errors, r_session
3206-
)
3207-
_validate_search_ids_with_ids(
3208-
search_url,
3209-
[items[0].get("id"), items[1].get("id")],
3210-
methods,
3211-
errors,
3212-
r_session,
3213-
)
3214-
_validate_search_ids_with_ids(
3215-
search_url, [i["id"] for i in items], methods, errors, r_session
3216-
)
3202+
if not body:
3203+
errors += f"[{Context.ITEM_SEARCH}] GET Search body was empty"
32173204
else:
3218-
warnings += f"[{Context.ITEM_SEARCH}] GET Search with no parameters returned < 2 results"
3205+
items = body.get("features") # type: ignore
3206+
if items and len(items) >= 2:
3207+
_validate_search_ids_with_ids(
3208+
search_url, [items[0].get("id")], methods, errors, r_session
3209+
)
3210+
_validate_search_ids_with_ids(
3211+
search_url,
3212+
[items[0].get("id"), items[1].get("id")],
3213+
methods,
3214+
errors,
3215+
r_session,
3216+
)
3217+
_validate_search_ids_with_ids(
3218+
search_url, [i["id"] for i in items], methods, errors, r_session
3219+
)
3220+
else:
3221+
warnings += f"[{Context.ITEM_SEARCH}] GET Search with no parameters returned < 2 results"
32193222

32203223

32213224
def validate_item_search_ids_does_not_override_all_other_params(
@@ -3236,7 +3239,7 @@ def validate_item_search_ids_does_not_override_all_other_params(
32363239
content_type=geojson_mt,
32373240
r_session=r_session,
32383241
)
3239-
if body.get("features"): # type: ignore
3242+
if body and body.get("features"): # type: ignore
32403243
_validate_search_ids_with_ids_no_override(
32413244
search_url,
32423245
body["features"][0],

0 commit comments

Comments
 (0)