Exception: Ingenico::Direct::SDK::ResponseException

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/ingenico/direct/sdk/response_exception.rb

Overview

Exception used internally in the SDK to indicate an error response was received from the Ingenico ePayments platform.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_code, headers, body) ⇒ ResponseException

Returns a new instance of ResponseException.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ingenico/direct/sdk/response_exception.rb', line 10

def initialize(status_code, headers, body)
  super('the Ingenico ePayments platform returned an error response')
  @status_code = status_code
  @headers = if headers.nil? || headers.empty?
               {}
             else
               headers.inject({}) do |hash, header|
                 hash[header.name.downcase.to_sym] = header.dup.freeze
                 hash
               end
             end.freeze
  @body = body
end

Instance Attribute Details

#bodyString (readonly)

HTTP message body that was returned by the Ingenico ePayments platform

Returns:

  • (String)

    the current value of body



8
9
10
# File 'lib/ingenico/direct/sdk/response_exception.rb', line 8

def body
  @body
end

#headersArray<Ingenico:Direct:SDK:ResponseHeader> (readonly)

HTTP headers used in the response from the Ingenico ePayments platform

Returns:

  • (Array<Ingenico:Direct:SDK:ResponseHeader>)

    the current value of headers



8
9
10
# File 'lib/ingenico/direct/sdk/response_exception.rb', line 8

def headers
  @headers
end

#status_codeInteger (readonly)

HTTP status code that was returned by the Ingenico ePayments platform

Returns:

  • (Integer)

    the current value of status_code



8
9
10
# File 'lib/ingenico/direct/sdk/response_exception.rb', line 8

def status_code
  @status_code
end

Instance Method Details

#get_header(header_name) ⇒ Object

Returns the Ingenico::Direct::SDK::ResponseHeader that corresponds to the given header_name used in the HTTP response from the Ingenico ePayments platform, or nil if the header was not present in the response.



30
31
32
# File 'lib/ingenico/direct/sdk/response_exception.rb', line 30

def get_header(header_name)
  ResponseHeader.get_header(@headers, header_name)
end

#get_header_value(header_name) ⇒ Object

Returns the header value received that corresponds to the header named by header_name, or nil if header_name was not a header present in the HTTP response.



36
37
38
# File 'lib/ingenico/direct/sdk/response_exception.rb', line 36

def get_header_value(header_name)
  ResponseHeader.get_header_value(@headers, header_name)
end

#to_sObject



40
41
42
43
44
45
# File 'lib/ingenico/direct/sdk/response_exception.rb', line 40

def to_s
  str = super.to_s
  str += "; status_code=#{@status_code}" if @status_code.positive?
  str += "; response_body='#{@body}'" if @body&.length.positive?
  str.to_s
end