class NxtHttpClient::Error

Attributes

id[R]
message[R]
response[R]
to_s[R]

Public Class Methods

new(response, message = nil) click to toggle source
Calls superclass method
# File lib/nxt_http_client/error.rb, line 3
def initialize(response, message = nil)
  @response = response.blank? ? Typhoeus::Response.new : response
  @id = SecureRandom.uuid
  @message = message || default_message

  super(@message)
end

Public Instance Methods

body() click to toggle source
# File lib/nxt_http_client/error.rb, line 33
def body
  if response_content_type&.starts_with?(ApplicationJson)
    JSON.parse(response.body)
  else
    response.body
  end
rescue ::JSON::JSONError
  response.body
end
default_message() click to toggle source
# File lib/nxt_http_client/error.rb, line 16
def default_message
  "#{self.class.name}::#{response_code}"
end
request() click to toggle source
# File lib/nxt_http_client/error.rb, line 47
def request
  @request ||= response.request || Typhoeus::Request.new('/dev/null', {})
end
request_headers() click to toggle source
# File lib/nxt_http_client/error.rb, line 63
def request_headers
  @request_headers ||= (request.original_options[:headers] || {}).with_indifferent_access
end
request_options() click to toggle source
# File lib/nxt_http_client/error.rb, line 59
def request_options
  @request_options ||= (request.original_options || {}).with_indifferent_access
end
response_code() click to toggle source
# File lib/nxt_http_client/error.rb, line 43
def response_code
  response.code || 0
end
response_content_type() click to toggle source
# File lib/nxt_http_client/error.rb, line 75
def response_content_type
  response_headers['Content-Type']
end
response_headers() click to toggle source
# File lib/nxt_http_client/error.rb, line 71
def response_headers
  @response_headers ||= (response.headers || {}).with_indifferent_access
end
response_options() click to toggle source
# File lib/nxt_http_client/error.rb, line 67
def response_options
  @response_options ||= (response.options || {}).with_indifferent_access
end
to_h() click to toggle source
# File lib/nxt_http_client/error.rb, line 20
def to_h
  {
    id: id,
    url: url,
    response_code: response_code,
    request_options: request_options,
    response_headers: response_headers,
    request_headers: request_headers,
    body: body,
    x_request_id: x_request_id
  }
end
url() click to toggle source
# File lib/nxt_http_client/error.rb, line 51
def url
  request.url
end
x_request_id() click to toggle source
# File lib/nxt_http_client/error.rb, line 55
def x_request_id
  request_headers[XRequestId]
end