Exception: PaypalClient::Errors::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/paypal_client/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error

Returns a new instance of Error.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/paypal_client/errors.rb', line 11

def initialize(response)
  @status_code = response.status
  @body = response.body

  if @body.class == Hash
    @error = @body[:name] if @body.key?(:name)
    @error_message = @body[:message] if @body.key?(:message)
  else
    @error = response.reason_phrase if @error.nil?
  end
  super(@error)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/paypal_client/errors.rb', line 7

def body
  @body
end

#errorObject (readonly)

Returns the value of attribute error.



8
9
10
# File 'lib/paypal_client/errors.rb', line 8

def error
  @error
end

#error_messageObject (readonly)

Returns the value of attribute error_message.



9
10
11
# File 'lib/paypal_client/errors.rb', line 9

def error_message
  @error_message
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



6
7
8
# File 'lib/paypal_client/errors.rb', line 6

def status_code
  @status_code
end

Instance Method Details

#inspectObject



24
25
26
27
28
29
# File 'lib/paypal_client/errors.rb', line 24

def inspect
  extra = ''
  extra << " status_code: #{status_code.inspect}" unless status_code.nil?
  extra << " body: #{body.inspect}"               unless body.nil?
  "#<#{self.class.name}: #{message}#{extra}>"
end