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
  @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

#to_sObject



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

def to_s
  prefix = code.nil? ? "" : "(Status #{code}) "
  suffix = " JSON: #{JSON.pretty_generate(json)}" if json
  "#{prefix}#{@message}" + (json ? suffix : "")
end