Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding error handling to dispatchers.
- Loading branch information
Michael Bleigh
committed
Mar 20, 2009
1 parent
a71312d
commit 97ea7aa
Showing
6 changed files
with
69 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module TwitterAuth | ||
module Dispatcher | ||
module Shared | ||
def handle_response(response) | ||
case response | ||
when Net::HTTPOK | ||
begin | ||
JSON.parse(response.body) | ||
rescue JSON::ParserError | ||
response.body | ||
end | ||
else | ||
message = begin | ||
JSON.parse(response.body)['error'] | ||
rescue JSON::ParserError | ||
if match = response.body.match(/<error>(.*)<\/error>/) | ||
match[1] | ||
else | ||
'An error occurred processing your Twitter request.' | ||
end | ||
end | ||
|
||
raise TwitterAuth::Dispatcher::Error, message | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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