better handling of API errors#110
Merged
ryanmcgrath merged 2 commits intoryanmcgrath:masterfrom Aug 25, 2012
Merged
Conversation
…I errors. this could likely be done a bit cleaner -- but this works.
twython/twython.py
Outdated
Collaborator
There was a problem hiding this comment.
Left some prints in here :P
Contributor
Author
There was a problem hiding this comment.
ha ha. thanks. fixing.
ryanmcgrath
pushed a commit
that referenced
this pull request
Aug 25, 2012
better handling of API errors
Owner
|
Mmm, this has been sitting for a bit now. Merged, will be pushed out in next release. Thanks! |
Contributor
Author
|
wonderful! thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I kept getting Twitter errors that said 'Response was not valid JSON, unable to decode.'
After a bit of debugging, I found out why -- my app uses an environment.ini file to change between dev and production modes -- with corresponding API keys. I was getting an Unauthorized error when i used the wrong ini , but the current codebase doesn't display that.
The current code will immediately raise an error on a failed decode -- however Twitter provides the 'unauthorized' info in the response header ( a bunch of other codes would fall in there too ).
This patch is pretty simple:
1_ it adds a 'json_error' variable, which is set to True on a failed load -- and defers raising an error for a bit...
2_ the current response.status_code check is left in tact
3_ it adds a block 'if json_error' to raise an error after the other error processing occurs
This could probably be cleaner, but then I'd have to rewrite a lot of stuff. this just works, right, and was fast.