Exception: Worldline::Acquiring::SDK::Communication::ResponseException
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- Worldline::Acquiring::SDK::Communication::ResponseException
- Defined in:
- lib/worldline/acquiring/sdk/communication/response_exception.rb
Overview
Exception used internally in the SDK to indicate an error response was received from the Worldline Acquiring platform.
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
HTTP message body that was returned by the Worldline Acquiring platform.
-
#headers ⇒ Array<Worldline::Acquiring::SDK::Communication::ResponseHeader>
readonly
HTTP headers used in the response from the Worldline Acquiring platform.
-
#status_code ⇒ Integer
readonly
HTTP status code that was returned by the Worldline Acquiring platform.
Instance Method Summary collapse
-
#get_header(header_name) ⇒ Object
Returns the ResponseHeader that corresponds to the given header_name used in the HTTP response from the Worldline Acquiring platform, or nil if the header was not present in the response.
-
#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.
-
#initialize(status_code, headers, body) ⇒ ResponseException
constructor
A new instance of ResponseException.
- #to_s ⇒ Object
Constructor Details
#initialize(status_code, headers, body) ⇒ ResponseException
Returns a new instance of ResponseException.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/worldline/acquiring/sdk/communication/response_exception.rb', line 14 def initialize(status_code, headers, body) super('the Worldline Acquiring platform returned an error response') @status_code = status_code @headers = if headers.nil? or 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
#body ⇒ String (readonly)
HTTP message body that was returned by the Worldline Acquiring platform
12 13 14 |
# File 'lib/worldline/acquiring/sdk/communication/response_exception.rb', line 12 def body @body end |
#headers ⇒ Array<Worldline::Acquiring::SDK::Communication::ResponseHeader> (readonly)
HTTP headers used in the response from the Worldline Acquiring platform
12 13 14 |
# File 'lib/worldline/acquiring/sdk/communication/response_exception.rb', line 12 def headers @headers end |
#status_code ⇒ Integer (readonly)
HTTP status code that was returned by the Worldline Acquiring platform
12 13 14 |
# File 'lib/worldline/acquiring/sdk/communication/response_exception.rb', line 12 def status_code @status_code end |
Instance Method Details
#get_header(header_name) ⇒ Object
Returns the Worldline::Acquiring::SDK::Communication::ResponseHeader that corresponds to the given header_name used in the HTTP response from the Worldline Acquiring platform, or nil if the header was not present in the response.
34 35 36 |
# File 'lib/worldline/acquiring/sdk/communication/response_exception.rb', line 34 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.
40 41 42 |
# File 'lib/worldline/acquiring/sdk/communication/response_exception.rb', line 40 def get_header_value(header_name) ResponseHeader.get_header_value(@headers, header_name) end |
#to_s ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/worldline/acquiring/sdk/communication/response_exception.rb', line 44 def to_s str = super.to_s if @status_code > 0 str += '; status_code=' + @status_code.to_s end if !@body.nil? && @body.length > 0 str += "; response_body='" + @body + "'" end str.to_s end |