-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[python-pytrakt] Feature: Throw BadResponseException on JSON decode errors #181
base: master
Are you sure you want to change the base?
Conversation
trakt/core.py
Outdated
try: | ||
json_data = json.loads(response.content.decode('UTF-8', 'ignore')) | ||
except JSONDecodeError as e: | ||
raise errors.BadResponseException(f"Unable to parse JSON: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe should add a specific JsonDecodeException here?
@@ -32,6 +38,12 @@ def __str__(self): | |||
return self.message | |||
|
|||
|
|||
class BadResponseException(TraktException): | |||
"""TraktException type to be raised when json could not be decoded""" | |||
http_code = -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used negative code for internal errors sp the positive numbers could be mapped to HTTP status codes
trakt/core.py
Outdated
json_data = json.loads(response.content.decode('UTF-8', 'ignore')) | ||
except JSONDecodeError as e: | ||
ex = errors.BadResponseException(response) | ||
ex.details = f"Unable to parse JSON: {e}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or better add as constructor argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another fresh error: The specific exception would allow to figure out url and status code ( |
a4106cd
to
0e92938
Compare
yet another json decode error #194 |
0e92938
to
27d90b1
Compare
This would be great to have, please merge, thank you! |
Carried: |
Many
JSONDecodeError
(from json module) are actually thrown because trakt.tv site responds with a status code that is not yet recognized by this library:Add fallback logic to be able to catch this specific error from applications.
Fixes #146