lib/coder_wally.rb in coder_wally-0.0.2 vs lib/coder_wally.rb in coder_wally-0.0.3

- old
+ new

@@ -20,10 +20,25 @@ end def CoderWally.get_badges_for username raise(ArgumentError, "Plesae provide a username") if username.empty? url = URI.parse(Url % username) - response = JSON.load(open(url)) - + + begin + request = open(url) + rescue OpenURI::HTTPError => error + raise UserNotFoundError, "User not found" if error.io.status[0] == "404" + raise ServerError, "Server error" if error.io.status[0] == "500" + end + + response = JSON.load(request) + response["badges"].map { |badge| Badge.new(badge) } + # end end + +class UserNotFoundError < StandardError +end + +class ServerError < StandardError +end \ No newline at end of file