better handling of API errors #110

Merged
jvanasco merged 2 commits from master into master 2012-08-25 16:30:03 -07:00
jvanasco commented 2012-08-01 10:40:36 -07:00 (Migrated from github.com)

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.

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.
ryanmcgrath commented 2012-08-25 16:30:29 -07:00 (Migrated from github.com)

Mmm, this has been sitting for a bit now. Merged, will be pushed out in next release. Thanks!

Mmm, this has been sitting for a bit now. Merged, will be pushed out in next release. Thanks!
jvanasco commented 2012-08-26 16:49:44 -07:00 (Migrated from github.com)

wonderful! thanks!

wonderful! thanks!
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: code/twython#110
No description provided.