Skip to content

Commit 11a7f46

Browse files
mattaschmannMatt Aschmann
andauthored
Handle exceeding the limit gracefully (geopython#2067)
* feat: Handle exceeding the limit gracefully Will now return a 400 to the user with info what the limit was that caused the error. * fix: fix test for evaluate_limit --------- Co-authored-by: Matt Aschmann <[email protected]>
1 parent 474a316 commit 11a7f46

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

pygeoapi/api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ def evaluate_limit(requested: Union[None, int], server_limits: dict,
16701670
if requested2 <= 0:
16711671
raise ValueError('limit value should be strictly positive')
16721672
elif requested2 > max_ and on_exceed == 'error':
1673-
raise RuntimeError('Limit exceeded; throwing errror')
1673+
raise ValueError(f'Limit of {max_} exceeded')
16741674
else:
16751675
LOGGER.debug('limit requested')
16761676
return min(requested2, max_)

tests/api/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ def test_evaluate_limit():
879879
collection = {}
880880
server = {'default_items': 2, 'max_items': 3, 'on_exceed': 'error'}
881881

882-
with pytest.raises(RuntimeError):
882+
with pytest.raises(ValueError):
883883
assert evaluate_limit('40', server, collection) == 40
884884

885885
collection = {'default_items': 10}

0 commit comments

Comments
 (0)