class ChefCLI::ServiceExceptionInspectors::HTTP

def attempt_error_message_extract

def attempt_error_message_extract
  error_body = FFI_Yajl::Parser.parse(response_body)
  if error_body.respond_to?(:key?) && error_body.key?("error")
    Array(error_body["error"]).join(", ")
  else
    error_body.to_s
  end
rescue
  response_body
end

def code

def code
  response.code
end

def extended_error_info

def extended_error_info
  <<~END
    --- RESPONSE DATA ---
    #{code} #{response_message}
    #{response_headers}
    #{response_body}
  END
end

def initialize(exception)

def initialize(exception)
  @exception = exception
end

def message

def message
  "HTTP #{code} #{response_message}: " + parsed_response_body
end

def parsed_response_body

def parsed_response_body
  if response_body && !response_body.empty?
    attempt_error_message_extract
  else
    "(No explanation provided by server)"
  end
end

def response

def response
  exception.response
end

def response_body

def response_body
  response.body
end

def response_headers

def response_headers
  headers_s = ""
  response.each_header do |key, value|
    headers_s << key << ": " << value << "\n"
  end
  headers_s
end

def response_message

def response_message
  response.message
end

def uri

def uri
  request.uri.to_s + request.path.to_s
end