Exception: Paid::APIError

Inherits:
PaidError
  • Object
show all
Defined in:
lib/paid/errors/api_error.rb

Direct Known Subclasses

APIConnectionError, AuthenticationError

Instance Attribute Summary collapse

Attributes inherited from PaidError

#message

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, api_method = nil) ⇒ APIError

Returns a new instance of APIError.



5
6
7
8
# File 'lib/paid/errors/api_error.rb', line 5

def initialize(message = nil, api_method = nil)
  @message = message || response_message
  @api_method = api_method
end

Instance Attribute Details

#api_methodObject (readonly)

Returns the value of attribute api_method.



3
4
5
# File 'lib/paid/errors/api_error.rb', line 3

def api_method
  @api_method
end

Instance Method Details

#bodyObject



14
15
16
# File 'lib/paid/errors/api_error.rb', line 14

def body
  @api_method.response_body if @api_method
end

#codeObject



10
11
12
# File 'lib/paid/errors/api_error.rb', line 10

def code
  @api_method.response_code if @api_method
end

#jsonObject



18
19
20
21
22
23
24
# File 'lib/paid/errors/api_error.rb', line 18

def json
  begin
    @api_method.response_json if @api_method
  rescue APIError
    nil
  end
end

#response_messageObject



26
27
28
29
30
31
32
# File 'lib/paid/errors/api_error.rb', line 26

def response_message
  begin
    json[:error][:message]
  rescue
    nil
  end
end

#to_sObject



34
35
36
37
38
39
40
# File 'lib/paid/errors/api_error.rb', line 34

def to_s
  if code.nil?
    return @message
  else
    return "(Status #{code}) #{@message}"
  end
end