better handling of API errors #110
No reviewers
Labels
No labels
Bug
Enhancement
Feature Suggestion
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: code/twython#110
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
Mmm, this has been sitting for a bit now. Merged, will be pushed out in next release. Thanks!
wonderful! thanks!