Class: ChefDK::ServiceExceptionInspectors::HTTP
- Inherits:
-
Object
- Object
- ChefDK::ServiceExceptionInspectors::HTTP
- Defined in:
- lib/chef-dk/service_exception_inspectors/http.rb
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
Instance Method Summary collapse
- #attempt_error_message_extract ⇒ Object
- #code ⇒ Object
- #extended_error_info ⇒ Object
- #http_method ⇒ Object
-
#initialize(exception) ⇒ HTTP
constructor
A new instance of HTTP.
- #message ⇒ Object
- #parsed_response_body ⇒ Object
- #req_body ⇒ Object
- #request ⇒ Object
- #request_headers ⇒ Object
- #response ⇒ Object
- #response_body ⇒ Object
- #response_headers ⇒ Object
- #response_message ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(exception) ⇒ HTTP
Returns a new instance of HTTP.
26 27 28 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 26 def initialize(exception) @exception = exception end |
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
24 25 26 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 24 def exception @exception end |
Instance Method Details
#attempt_error_message_extract ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 74 def 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 |
#code ⇒ Object
54 55 56 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 54 def code response.code end |
#extended_error_info ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 34 def extended_error_info <<~END --- REQUEST DATA ---- #{http_method} #{uri} #{request_headers} #{req_body} --- RESPONSE DATA --- #{code} #{} #{response_headers} #{response_body} END end |
#http_method ⇒ Object
101 102 103 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 101 def http_method request.method end |
#message ⇒ Object
30 31 32 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 30 def "HTTP #{code} #{}: " + parsed_response_body end |
#parsed_response_body ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 66 def parsed_response_body if response_body && !response_body.empty? else "(No explanation provided by server)" end end |
#req_body ⇒ Object
113 114 115 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 113 def req_body request.body end |
#request ⇒ Object
93 94 95 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 93 def request exception.chef_rest_request end |
#request_headers ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 105 def request_headers headers_s = "" request.each_header do |key, value| headers_s << key << ": " << value << "\n" end headers_s end |
#response ⇒ Object
50 51 52 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 50 def response exception.response end |
#response_body ⇒ Object
62 63 64 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 62 def response_body response.body end |
#response_headers ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 85 def response_headers headers_s = "" response.each_header do |key, value| headers_s << key << ": " << value << "\n" end headers_s end |
#response_message ⇒ Object
58 59 60 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 58 def response. end |
#uri ⇒ Object
97 98 99 |
# File 'lib/chef-dk/service_exception_inspectors/http.rb', line 97 def uri request.uri.to_s + request.path.to_s end |