Skip to content

Commit a91911a

Browse files
committed
fix exception if post not supported by server
1 parent 9374014 commit a91911a

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ and then run it:
4141
```console
4242
$ stac-api-validator \
4343
--root-url https://planetarycomputer.microsoft.com/api/stac/v1/ \
44-
--conformance core --conformance item-search
44+
--conformance core \
45+
--conformance item-search \
46+
--collection sentinel-2-l2a \
47+
--geometry '{"type": "Polygon", "coordinates": [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]]}'
4548
```
4649

4750
## Contributing
@@ -53,6 +56,14 @@ To learn more, see the [Contributor Guide].
5356

5457
Please see the [Command-line Reference] for details.
5558

59+
The conformance class validations to run are selected with the `--conformance` parameters. This parameter
60+
can be used more than once to specify multiple conformance classes to validate. The `STAC API - Core` conformance
61+
class will always be validated, even if not specified.
62+
63+
If `item-search`, `collections`, and/or `features` are specified, the `--collection` and `--geometry` parameters must also
64+
be specified. The `--collection` parameter specifies the name of a collection to use for some of the validations.
65+
The `--geometry` should specify an AOI over which there are some results in that collection.
66+
5667
## Features
5768

5869
**Work in Progress** -- this currently only validates a subset of behavior

src/stac_api_validator/validations.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,17 +1321,24 @@ def _validate_search_ids_with_ids_no_override(
13211321
}
13221322

13231323
r = requests.get(search_url, params=get_params)
1324-
try:
1325-
if len(r.json().get("features")) > 0:
1326-
errors.append(
1327-
"GET Search with ids and non-intersecting bbox returned results, indicating "
1328-
"the ids parameter is overriding the bbox parameter. All parameters are applied equally since "
1329-
"STAC API 1.0.0-beta.1"
1330-
)
1331-
except json.decoder.JSONDecodeError:
1324+
1325+
if not (r.status_code == 200):
13321326
errors.append(
1333-
f"GET Search with {get_params} returned non-json response: {r.text}"
1327+
f"GET Search with id and other parameters returned status code {r.status_code}"
13341328
)
1329+
else:
1330+
1331+
try:
1332+
if len(r.json().get("features", [])) > 0:
1333+
errors.append(
1334+
"GET Search with ids and non-intersecting bbox returned results, indicating "
1335+
"the ids parameter is overriding the bbox parameter. All parameters are applied equally since "
1336+
"STAC API 1.0.0-beta.1"
1337+
)
1338+
except json.decoder.JSONDecodeError:
1339+
errors.append(
1340+
f"GET Search with {get_params} returned non-json response: {r.text}"
1341+
)
13351342

13361343
if post:
13371344
post_params = {
@@ -1342,17 +1349,22 @@ def _validate_search_ids_with_ids_no_override(
13421349

13431350
r = requests.post(search_url, json=post_params)
13441351

1345-
try:
1346-
if len(r.json().get("features")) > 0:
1347-
errors.append(
1348-
"POST Search with ids and non-intersecting bbox returned results, indicating "
1349-
"the ids parameter is overriding the bbox parameter. All parameters are applied equally since "
1350-
"STAC API 1.0.0-beta.1"
1351-
)
1352-
except json.decoder.JSONDecodeError:
1352+
if not (r.status_code == 200):
13531353
errors.append(
1354-
f"POST Search with {get_params} returned non-json response: {r.text}"
1354+
f"POST Search with id and other parameters returned status code {r.status_code}"
13551355
)
1356+
else:
1357+
try:
1358+
if len(r.json().get("features", [])) > 0:
1359+
errors.append(
1360+
"POST Search with ids and non-intersecting bbox returned results, indicating "
1361+
"the ids parameter is overriding the bbox parameter. All parameters are applied equally since "
1362+
"STAC API 1.0.0-beta.1"
1363+
)
1364+
except json.decoder.JSONDecodeError:
1365+
errors.append(
1366+
f"POST Search with {get_params} returned non-json response: {r.text}"
1367+
)
13561368

13571369

13581370
def validate_item_search_ids(

0 commit comments

Comments
 (0)