Skip to content
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

Handle API errors in SparkPostAPIException #96

Closed
wants to merge 4 commits into from

Conversation

pegler
Copy link
Contributor

@pegler pegler commented Mar 29, 2016

When the API returns 5xx errors, the response typically does not actually include any json, which causes JSONDecodeErrors to be raised by response.json(). This branch addresses that issue by only parsing the response as json if the content-type response header is set correctly.

Additionally, it sets response_status_code and response_errors_codes on the SparkPostAPIException so that applications can catch the exception and react accordingly. 5xx errors should usually be retried, while 4xx errors sometimes should be retried (rate limit) and other times be fatal (recipient on suppression list).

@richleland
Copy link
Contributor

Ah cool there is some overlap here with an open PR - check out https://github.com/SparkPost/python-sparkpost/pull/94/files#diff-bf66564894a4a13c92ffe4ebed2d79d8L5 - mind commenting and discussing with @friedcell about it over on that PR?

@richleland
Copy link
Contributor

Merged in #94, which contains similar additions to the exception class.

@richleland richleland closed this Mar 30, 2016
@pegler pegler deleted the handle-504 branch April 28, 2016 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants