Skip to content

Tweaks to exception handling #135

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

Merged
merged 3 commits into from
Jan 13, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Catch more than JSON parsing errors
  • Loading branch information
Rich Leland committed Jan 12, 2017
commit f99e3fc06ca584744bfb84357391c0eeae3d81b9
3 changes: 1 addition & 2 deletions sparkpost/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ class SparkPostException(Exception):
class SparkPostAPIException(SparkPostException):
"Handle 4xx and 5xx errors from the SparkPost API"
def __init__(self, response, *args, **kwargs):
errors = None
try:
errors = response.json()['errors']
error_template = "{message} Code: {code} Description: {desc} \n"
errors = [error_template.format(message=e['message'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we use e.get('message') here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we could - though if message isn't there this is useless to users - I could go either way w/it

code=e.get('code', 'none'),
desc=e.get('description', 'none'))
for e in errors]
except ValueError:
except:
errors = [response.text or ""]
self.status = response.status_code
self.response = response
Expand Down