Permalink
Browse files

Do the right thing with rest-clients http_code.

Switch from manually trying to parse out a number from error.to_s to using
the right method to get the acutal response code.
  • Loading branch information...
dakrone committed Jul 7, 2010
1 parent ac3e4d3 commit 264e9db951a796961eb13cda22523d72380b4e14
Showing with 6 additions and 11 deletions.
  1. +6 −11 lib/ricepaper.rb
View
@@ -24,17 +24,12 @@ def initialize(username, password, apiurl = "https://www.instapaper.com/api/")
# Handle Errors - sets the error code appropriately
# so that it can be reported
def handle_error(err)
- if err.to_s == "Forbidden"
- @error = "Invalid username or password"
- else
- result = /(\d+)/.match(err.to_s)[1]
- @error = case result
- when "400" then "Bad Request"
- when "403" then "Invalid username or password"
- when "500" then "There was a server error. Please try again later."
- else "An unknown error occured"
- end
- end
+ @error = case err.http_code
+ when 400 then "Bad Request"
+ when 403 then "Invalid username or password"
+ when 500 then "There was a server error. Please try again later."
+ else "An unknown error occured"
+ end
end
# Authenticate with instapaper, returning true if auth

0 comments on commit 264e9db

Please sign in to comment.