Exception: Pin::PinError
- Inherits:
-
Exception
- Object
- Exception
- Pin::PinError
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
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
30
31
32
33
34
35
36
37
38
|
# 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 = ""
begin
response['messages'].each do |m|
message += "#{m['code']}: #{m['message']}"
end
rescue
begin response['messages']['amount'][0]
message = "#{response['error']}: #{response['error_description']}. Amount: #{response['messages']['amount'][0]}"
rescue
message = "#{response['error']}: #{response['error_description']}"
end
end
raise(Pin::InvalidResource, message)
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
|