Skip to content

Commit 9f9a3d2

Browse files
Return empty array instead of raising NoResultsError for missing results (#483)
* Return empty array instead of raising NoResultsError for missing results
1 parent a7f001c commit 9f9a3d2

File tree

3 files changed

+4
-21
lines changed

3 files changed

+4
-21
lines changed

docs/source/Exceptions.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,3 @@ BadResponse
1717
:members:
1818
:undoc-members:
1919

20-
==============================================================
21-
NoResultsError
22-
==============================================================
23-
.. autoclass:: polygon.exceptions.NoResultsError
24-
:members:
25-
:undoc-members:
26-

polygon/exceptions.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,3 @@ class BadResponse(Exception):
1212
"""
1313

1414
pass
15-
16-
17-
class NoResultsError(Exception):
18-
"""
19-
Missing results key
20-
"""
21-
22-
pass

polygon/rest/base.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ..logging import get_logger
1111
import logging
1212
from urllib.parse import urlencode
13-
from ..exceptions import AuthError, BadResponse, NoResultsError
13+
from ..exceptions import AuthError, BadResponse
1414

1515
logger = get_logger("RESTClient")
1616
version = "unknown"
@@ -116,11 +116,7 @@ def _get(
116116

117117
if result_key:
118118
if result_key not in obj:
119-
raise NoResultsError(
120-
f'Expected key "{result_key}" in response {obj}.'
121-
+ "Make sure you have sufficient permissions and your request parameters are valid."
122-
+ f"This is the url that returned no results: {resp.geturl()}"
123-
)
119+
return []
124120
obj = obj[result_key]
125121

126122
if deserializer:
@@ -198,6 +194,8 @@ def _paginate_iter(
198194
options=options,
199195
)
200196
decoded = self._decode(resp)
197+
if result_key not in decoded:
198+
return []
201199
for t in decoded[result_key]:
202200
yield deserializer(t)
203201
if "next_url" in decoded:

0 commit comments

Comments
 (0)