Exception: Pin::PinError
- Inherits:
-
Exception
- Object
- Exception
- Pin::PinError
- Defined in:
- lib/pin_up/pin_errors.rb
Direct Known Subclasses
ChargeError, InsufficientPinBalance, InvalidResource, ResourceNotFound
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(message = nil, http_status = nil) ⇒ PinError
constructor
A new instance of PinError.
- #to_s ⇒ Object
Constructor Details
#initialize(message = nil, http_status = nil) ⇒ PinError
Returns a new instance of PinError.
4 5 6 7 |
# File 'lib/pin_up/pin_errors.rb', line 4 def initialize(=nil, http_status=nil) @message = @http_status = http_status end |
Class Method Details
.handle_error(http_status, response) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pin_up/pin_errors.rb', line 14 def self.handle_error(http_status, response) case http_status when 400 raise(Pin::ChargeError, "#{response['error']}: #{response['error_description']}. Charge token: #{response['charge_token']}") when 402 raise(Pin::InsufficientPinBalance, "#{response['error_description']}") when 404 raise(Pin::ResourceNotFound, "#{response['error_description']}") when 422 = "" response['messages'].each do |m| += "#{m['code']}: #{m['message']}" end raise(Pin::InvalidResource, ) end end |
Instance Method Details
#to_s ⇒ Object
9 10 11 12 |
# File 'lib/pin_up/pin_errors.rb', line 9 def to_s status_string = @http_status.nil? ? "" : "(Status #{@http_status}) " "#{status_string}#{@message}" end |