Skip to content

Commit 1959639

Browse files
Handle JSON decoding errors in _get and _paginate_iter (#500)
1 parent e77c22b commit 1959639

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

polygon/rest/base.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ def _get(
112112
if raw:
113113
return resp
114114

115-
obj = self._decode(resp)
115+
try:
116+
obj = self._decode(resp)
117+
except ValueError as e:
118+
print(f"Error decoding json response: {e}")
119+
return []
116120

117121
if result_key:
118122
if result_key not in obj:
@@ -193,7 +197,13 @@ def _paginate_iter(
193197
raw=True,
194198
options=options,
195199
)
196-
decoded = self._decode(resp)
200+
201+
try:
202+
decoded = self._decode(resp)
203+
except ValueError as e:
204+
print(f"Error decoding json response: {e}")
205+
return []
206+
197207
if result_key not in decoded:
198208
return []
199209
for t in decoded[result_key]:

0 commit comments

Comments
 (0)