Class: ChefCLI::ServiceExceptionInspectors::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-cli/service_exception_inspectors/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception) ⇒ HTTP

Returns a new instance of HTTP.



26
27
28
# File 'lib/chef-cli/service_exception_inspectors/http.rb', line 26

def initialize(exception)
  @exception = exception
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



24
25
26
# File 'lib/chef-cli/service_exception_inspectors/http.rb', line 24

def exception
  @exception
end

Instance Method Details

#attempt_error_message_extractObject



68
69
70
71
72
73
74
75
76
77
# File 'lib/chef-cli/service_exception_inspectors/http.rb', line 68

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

#codeObject



48
49
50
# File 'lib/chef-cli/service_exception_inspectors/http.rb', line 48

def code
  response.code
end

#extended_error_infoObject



34
35
36
37
38
39
40
41
42
# File 'lib/chef-cli/service_exception_inspectors/http.rb', line 34

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

    #{response_body}
  END
end

#messageObject



30
31
32
# File 'lib/chef-cli/service_exception_inspectors/http.rb', line 30

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

#parsed_response_bodyObject



60
61
62
63
64
65
66
# File 'lib/chef-cli/service_exception_inspectors/http.rb', line 60

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

#responseObject



44
45
46
# File 'lib/chef-cli/service_exception_inspectors/http.rb', line 44

def response
  exception.response
end

#response_bodyObject



56
57
58
# File 'lib/chef-cli/service_exception_inspectors/http.rb', line 56

def response_body
  response.body
end

#response_headersObject



79
80
81
82
83
84
85
# File 'lib/chef-cli/service_exception_inspectors/http.rb', line 79

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

#response_messageObject



52
53
54
# File 'lib/chef-cli/service_exception_inspectors/http.rb', line 52

def response_message
  response.message
end

#uriObject



87
88
89
# File 'lib/chef-cli/service_exception_inspectors/http.rb', line 87

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