Permalink
Browse files

Refactor ClientErrors. Add UnknownDeviceError.

  • Loading branch information...
1 parent c1d345f commit 1330563ef69ccdc7a03deaf40406e2bfb68716d6 @roelbondoc committed Apr 16, 2012
Showing with 12 additions and 9 deletions.
  1. +7 −5 lib/five_mobile_push.rb
  2. +2 −1 lib/five_mobile_push/client.rb
  3. +3 −3 spec/integration/client_spec.rb
View
@@ -11,11 +11,13 @@ module FiveMobilePush
autoload :Message, 'five_mobile_push/message'
autoload :Platform, 'five_mobile_push/platform'
- class UnauthorizedError < StandardError; end
- class GeneralError < StandardError; end
- class ServerError < StandardError; end
- class InvalidPlatformError < StandardError; end
- class InvalidToken < StandardError; end
+ class ClientError < StandardError; end
+ class UnauthorizedError < ClientError; end
+ class GeneralError < ClientError; end
+ class ServerError < ClientError; end
+ class InvalidPlatformError < ClientError; end
+ class InvalidTokenError < ClientError; end
+ class UnknownDeviceError < ClientError; end
DEFAULT_ID_TYPE = 'native'
@@ -48,7 +48,8 @@ def perform_request(method, path, options={})
# TODO Add error processor here.
# Basic error checking
if resp.status == 400
- raise InvalidToken if resp.body =~ /Invalid API token/i
+ raise InvalidTokenError if resp.body =~ /Invalid API token/i
+ raise UnknownDeviceError if resp.body =~ /Unknown device/i
end
resp
@@ -88,12 +88,12 @@ def unregister_device(device)
resp.body.should == ''
end
- it 'raises an InvalidToken exception for an invalid device' do
+ it 'raises an InvalidTokenError exception for an invalid device' do
unregister_device(device) # Once to clean up...
expect {
unregister_device(device) # Again to cause an error...
- }.to raise_error(FiveMobilePush::InvalidToken)
+ }.to raise_error(FiveMobilePush::InvalidTokenError)
end
end
@@ -115,7 +115,7 @@ def unregister_device(device)
it 'suspends with an invalid token' do
expect {
subject.device(device.uid, 'wooohoo').suspend
- }.to raise_error(FiveMobilePush::InvalidToken)
+ }.to raise_error(FiveMobilePush::InvalidTokenError)
end
it 'resumes a subscription' do

0 comments on commit 1330563

Please sign in to comment.