Exception: OCI::Errors::ResponseParsingError

Inherits:
HttpRequestBasedError show all
Defined in:
lib/oci/errors.rb

Overview

The base error for issues related to parsing the response received from the service. The #response_body can be inspected for the data which failed to parse and the #cause of this error can be inspected for the underlying parsing error which occurred

Instance Attribute Summary collapse

Attributes inherited from HttpRequestBasedError

#message, #request_id, #request_made

Instance Method Summary collapse

Constructor Details

#initialize(message: 'Failed to parse response', request_made:, response_received:) ⇒ ResponseParsingError

Returns a new instance of ResponseParsingError.



129
130
131
132
133
134
135
136
137
# File 'lib/oci/errors.rb', line 129

def initialize(message: 'Failed to parse response', request_made:, response_received:)
  raise 'A message must be provided' if message.nil? || message.strip.empty?
  raise 'The request made must be provided' if request_made.nil?
  raise 'The response received must be provided' if response_received.nil?

  super(message: message, request_made: request_made)
  @response_received = response_received
  @request_id = @response_received['opc-request-id'] unless @response_received['opc-request-id'].nil?
end

Instance Attribute Details

#response_receivedNet::HTTPResponse (readonly)

The response received for the request, and whose body we failed to parse

Returns:

  • (Net::HTTPResponse)


127
128
129
# File 'lib/oci/errors.rb', line 127

def response_received
  @response_received
end

Instance Method Details

#response_bodyString

The response body which we failed to parse

Returns:

  • (String)


142
143
144
# File 'lib/oci/errors.rb', line 142

def response_body
  response_received.body
end

#status_codeInteger

The status code of the response (e.g. 200)

Returns:

  • (Integer)


149
150
151
# File 'lib/oci/errors.rb', line 149

def status_code
  response_received.code.to_i
end

#to_sObject



153
154
155
156
# File 'lib/oci/errors.rb', line 153

def to_s
  "{ 'message': '#{message}', 'status': #{status_code}, " \
  "'opc-request-id': '#{request_id}', 'response-body': '#{response_body}' }"
end