Skip to content

Commit

Permalink
Handle unknown response codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
david committed Jul 6, 2011
1 parent 17f547b commit f86567a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/hipchat.rb
Expand Up @@ -2,8 +2,9 @@
require 'ostruct'

module HipChat
class UnknownRoom < StandardError; end
class Unauthorized < StandardError; end
class UnknownRoom < StandardError; end
class Unauthorized < StandardError; end
class UnknownResponseCode < StandardError; end

class Client
include HTTParty
Expand Down Expand Up @@ -49,6 +50,9 @@ def send(from, message, notify = false)
when 200; # weee
when 404; raise UnknownRoom, "Unknown room: `#{room_id}'"
when 401; raise Unauthorized, "Access denied to room `#{room_id}'"
else raise UnknownResponseCode, "Unexpected #{response.code} for " <<
"room `#{room_id}'"

end
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/hipchat_spec.rb
Expand Up @@ -34,5 +34,14 @@

lambda { room.send "", "" }.should raise_error(HipChat::Unauthorized)
end

it "but fails if we get an unknown response code" do
mock(HipChat::Room).post(anything, anything) {
OpenStruct.new(:code => 403)
}

lambda { room.send "", "" }.
should raise_error(HipChat::UnknownResponseCode)
end
end
end

0 comments on commit f86567a

Please sign in to comment.