Exception: Pin::PinError

Inherits:
Exception
  • Object
show all
Defined in:
lib/pin_up/pin_errors.rb

Class Method Summary collapse

Instance Method Summary collapse

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(message=nil, http_status=nil)
  @message = 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
    message = ""
    response['messages'].each do |m|
      message += "#{m['code']}: #{m['message']}"
    end
    raise(Pin::InvalidResource, message)
  end
end

Instance Method Details

#to_sObject



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