Exception: PostcodeAnywhere::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/postcode_anywhere/error.rb

Overview

Custom error class for rescuing from all PostcodeAnywhere errors

Constant Summary collapse

ClientError =
Class.new(self)
BadRequest =
Class.new(ClientError)
Unauthorized =
Class.new(ClientError)
Forbidden =
Class.new(ClientError)
NotFound =
Class.new(ClientError)
NotAcceptable =
Class.new(ClientError)
RequestTimeout =
Class.new(ClientError)
UnprocessableEntity =
Class.new(ClientError)
TooManyRequests =
Class.new(ClientError)
ServerError =
Class.new(self)
InternalServerError =
Class.new(ServerError)
BadGateway =
Class.new(ServerError)
ServiceUnavailable =
Class.new(ServerError)
GatewayTimeout =
Class.new(ServerError)
UnknownError =

Postcode anywhere specific errors

Class.new(ServerError)
UnknownKey =
Class.new(ClientError)
AccountOutOfCredit =
Class.new(Forbidden)
IpDenied =
Class.new(Forbidden)
UrlDenied =
Class.new(Forbidden)
ServiceDeniedForKey =
Class.new(Forbidden)
ServiceDeniedForPlan =
Class.new(Forbidden)
KeyDailyLimitExceeded =
Class.new(Forbidden)
SurgeProtectorRunning =
Class.new(Forbidden)
SurgeProtectorTriggered =
Class.new(Forbidden)
NoValidLicense =
Class.new(Forbidden)
ManagementKeyRequired =
Class.new(Forbidden)
DemoLimitExceeded =
Class.new(Forbidden)
FreeLimitExceeded =
Class.new(Forbidden)
IncorrectKeyType =
Class.new(Forbidden)
KeyExpired =
Class.new(Forbidden)
ServiceSpecificError =
Class.new(ClientError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description = '', code = nil, cause = '', resolution = '') ⇒ Error

Returns a new instance of Error.



75
76
77
78
79
80
# File 'lib/postcode_anywhere/error.rb', line 75

def initialize(description = '', code = nil, cause = '', resolution = '')
  super(description)
  @code = code
  @cause = cause
  @resolution = resolution
end

Instance Attribute Details

#causeObject (readonly)

Returns the value of attribute cause.



5
6
7
# File 'lib/postcode_anywhere/error.rb', line 5

def cause
  @cause
end

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/postcode_anywhere/error.rb', line 4

def code
  @code
end

#resolutionObject (readonly)

Returns the value of attribute resolution.



6
7
8
# File 'lib/postcode_anywhere/error.rb', line 6

def resolution
  @resolution
end

Class Method Details

.errorsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/postcode_anywhere/error.rb', line 14

def errors
  @errors ||= {
    400 => PostcodeAnywhere::Error::BadRequest,
    401 => PostcodeAnywhere::Error::Unauthorized,
    403 => PostcodeAnywhere::Error::Forbidden,
    404 => PostcodeAnywhere::Error::NotFound,
    406 => PostcodeAnywhere::Error::NotAcceptable,
    408 => PostcodeAnywhere::Error::RequestTimeout,
    422 => PostcodeAnywhere::Error::UnprocessableEntity,
    429 => PostcodeAnywhere::Error::TooManyRequests,
    500 => PostcodeAnywhere::Error::InternalServerError,
    502 => PostcodeAnywhere::Error::BadGateway,
    503 => PostcodeAnywhere::Error::ServiceUnavailable,
    504 => PostcodeAnywhere::Error::GatewayTimeout
  }
end

.from_response(error_hash) ⇒ Object



9
10
11
12
# File 'lib/postcode_anywhere/error.rb', line 9

def from_response(error_hash)
  message, code, cause, resolution = parse_error(error_hash)
  new(message, code, cause, resolution)
end

.postcode_anywhere_errorsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/postcode_anywhere/error.rb', line 31

def postcode_anywhere_errors
  @postcode_anywhere_errors ||= {
    -1 => PostcodeAnywhere::Error::UnknownError,
    2  => PostcodeAnywhere::Error::UnknownKey,
    3  => PostcodeAnywhere::Error::AccountOutOfCredit,
    4  => PostcodeAnywhere::Error::IpDenied,
    5  => PostcodeAnywhere::Error::UrlDenied,
    6  => PostcodeAnywhere::Error::ServiceDeniedForKey,
    7  => PostcodeAnywhere::Error::ServiceDeniedForPlan,
    8  => PostcodeAnywhere::Error::KeyDailyLimitExceeded,
    9  => PostcodeAnywhere::Error::SurgeProtectorRunning,
    10 => PostcodeAnywhere::Error::SurgeProtectorTriggered,
    11 => PostcodeAnywhere::Error::NoValidLicense,
    12 => PostcodeAnywhere::Error::ManagementKeyRequired,
    13 => PostcodeAnywhere::Error::DemoLimitExceeded,
    14 => PostcodeAnywhere::Error::FreeLimitExceeded,
    15 => PostcodeAnywhere::Error::IncorrectKeyType,
    16 => PostcodeAnywhere::Error::KeyExpired,
    17 => PostcodeAnywhere::Error::KeyDailyLimitExceeded
  }
end