class ChimeraHttpClient::Error

Attributes

body[R]
code[R]
deserializer[R]
message[R]
response[R]
time[R]

Public Class Methods

new(response, options = {}) click to toggle source
Calls superclass method
# File lib/chimera_http_client/error.rb, line 6
def initialize(response, options = {})
  @body     = response.body
  @code     = response.code
  @time     = response.options&.fetch(:total_time, nil)
  @response = response # contains the request

  @deserializer = options[:deserializer][:error]

  super(response.body)
end

Public Instance Methods

error?() click to toggle source
# File lib/chimera_http_client/error.rb, line 21
def error?
  true
end
parsed_body() click to toggle source
# File lib/chimera_http_client/error.rb, line 25
def parsed_body
  deserializer.call(body)
end
success?() click to toggle source
# File lib/chimera_http_client/error.rb, line 17
def success?
  response.success?
end
to_json(_options = {}) click to toggle source
# File lib/chimera_http_client/error.rb, line 37
def to_json(_options = {})
  error = {
    code:        code,
    error_class: self.class.name,
    method:      http_method,
    url:         url,
    message:     message,
  }

  return error.merge({ request: response.request.inspect }).to_json if log_requests?

  error.to_json
end
to_s() click to toggle source
# File lib/chimera_http_client/error.rb, line 29
def to_s
  error = "#{self.class.name} (#{code}) #{message}, URL: #{url}"

  return "#{error}, Request: #{response.request.inspect}" if log_requests?

  error
end

Private Instance Methods

http_method() click to toggle source
# File lib/chimera_http_client/error.rb, line 57
def http_method
  response.request.options[:method]
end
log_requests?() click to toggle source
# File lib/chimera_http_client/error.rb, line 61
def log_requests?
  ENV["CHIMERA_HTTP_CLIENT_LOG_REQUESTS"] == true || ENV["CHIMERA_HTTP_CLIENT_LOG_REQUESTS"] == "true"
end
url() click to toggle source
# File lib/chimera_http_client/error.rb, line 53
def url
  response.request.base_url
end