class PostcodeAnywhere::Error
Custom error class for rescuing from all PostcodeAnywhere
errors
Constants
- AccountOutOfCredit
- BadGateway
- BadRequest
- ClientError
- DemoLimitExceeded
- Forbidden
- FreeLimitExceeded
- GatewayTimeout
- IncorrectKeyType
- InternalServerError
- IpDenied
- KeyDailyLimitExceeded
- KeyExpired
- ManagementKeyRequired
- NoValidLicense
- NotAcceptable
- NotFound
- RequestTimeout
- ServerError
- ServiceDeniedForKey
- ServiceDeniedForPlan
- ServiceSpecificError
- SurgeProtectorRunning
- SurgeProtectorTriggered
- TooManyRequests
- UnknownError
Postcode anywhere specific errors
- UnknownKey
- UnprocessableEntity
- UrlDenied
Attributes
cause[R]
code[R]
resolution[R]
Public Class Methods
errors()
click to toggle source
# 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)
click to toggle source
# 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
new(description = '', code = nil, cause = '', resolution = '')
click to toggle source
Calls superclass method
# File lib/postcode_anywhere/error.rb, line 75 def initialize(description = '', code = nil, cause = '', resolution = '') super(description) @code = code @cause = cause @resolution = resolution end
postcode_anywhere_errors()
click to toggle source
# 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
Private Class Methods
extract_message_from_error(body)
click to toggle source
# File lib/postcode_anywhere/error.rb, line 68 def extract_message_from_error(body) m = /The exception message is \'(.+)?\'\. See server logs for more details./.match(body) return m.captures.first if m end
parse_error(error_hash)
click to toggle source
# File lib/postcode_anywhere/error.rb, line 55 def parse_error(error_hash) if error_hash.nil? ['', nil, '', ''] else [ error_hash[:description], error_hash[:error], error_hash[:cause], error_hash[:resolution] ] end end