Module: Chef::Formatters::APIErrorFormatting
- Included in:
- ErrorInspectors::CookbookResolveErrorInspector, ErrorInspectors::CookbookSyncErrorInspector, ErrorInspectors::NodeLoadErrorInspector, ErrorInspectors::RunListExpansionErrorInspector
- Defined in:
- lib/chef/formatters/error_inspectors/api_error_formatting.rb
Constant Summary collapse
- NETWORK_ERROR_CLASSES =
[Errno::ECONNREFUSED, Timeout::Error, Errno::ETIMEDOUT, SocketError]
Instance Method Summary collapse
- #api_key ⇒ Object
- #clock_skew? ⇒ Boolean
- #describe_400_error(error_description) ⇒ Object
- #describe_401_error(error_description) ⇒ Object
- #describe_500_error(error_description) ⇒ Object
- #describe_503_error(error_description) ⇒ Object
-
#describe_http_error(error_description) ⇒ Object
Fallback for unexpected/uncommon http errors.
- #describe_network_errors(error_description) ⇒ Object
-
#format_rest_error ⇒ Object
Parses JSON from the error response sent by Chef Server and returns the error message.
- #server_url ⇒ Object
- #username ⇒ Object
Instance Method Details
#api_key ⇒ Object
97 98 99 |
# File 'lib/chef/formatters/error_inspectors/api_error_formatting.rb', line 97 def api_key config[:client_key] end |
#clock_skew? ⇒ Boolean
105 106 107 |
# File 'lib/chef/formatters/error_inspectors/api_error_formatting.rb', line 105 def clock_skew? exception.response.body =~ /synchronize the clock/i end |
#describe_400_error(error_description) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/chef/formatters/error_inspectors/api_error_formatting.rb', line 60 def describe_400_error(error_description) error_description.section("Invalid Request Data:",<<-E) The data in your request was invalid (HTTP 400). E error_description.section("Server Response:",format_rest_error) end |
#describe_401_error(error_description) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/chef/formatters/error_inspectors/api_error_formatting.rb', line 37 def describe_401_error(error_description) if clock_skew? error_description.section("Authentication Error:",<<-E) Failed to authenticate to the chef server (http 401). The request failed because your clock has drifted by more than 15 minutes. Syncing your clock to an NTP Time source should resolve the issue. E else error_description.section("Authentication Error:",<<-E) Failed to authenticate to the chef server (http 401). E error_description.section("Server Response:", format_rest_error) error_description.section("Relevant Config Settings:",<<-E) chef_server_url "#{server_url}" node_name "#{username}" client_key "#{api_key}" If these settings are correct, your client_key may be invalid. E end end |
#describe_500_error(error_description) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/chef/formatters/error_inspectors/api_error_formatting.rb', line 67 def describe_500_error(error_description) error_description.section("Unknown Server Error:",<<-E) The server had a fatal error attempting to load the node data. E error_description.section("Server Response:", format_rest_error) end |
#describe_503_error(error_description) ⇒ Object
74 75 76 77 |
# File 'lib/chef/formatters/error_inspectors/api_error_formatting.rb', line 74 def describe_503_error(error_description) error_description.section("Server Unavailable","The Chef Server is temporarily unavailable") error_description.section("Server Response:", format_rest_error) end |
#describe_http_error(error_description) ⇒ Object
Fallback for unexpected/uncommon http errors
81 82 83 |
# File 'lib/chef/formatters/error_inspectors/api_error_formatting.rb', line 81 def describe_http_error(error_description) error_description.section("Unexpected API Request Failure:", format_rest_error) end |
#describe_network_errors(error_description) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/chef/formatters/error_inspectors/api_error_formatting.rb', line 26 def describe_network_errors(error_description) error_description.section("Networking Error:",<<-E) #{exception.} Your chef_server_url may be misconfigured, or the network could be down. E error_description.section("Relevant Config Settings:",<<-E) chef_server_url "#{server_url}" E end |
#format_rest_error ⇒ Object
Parses JSON from the error response sent by Chef Server and returns the error message
87 88 89 90 91 |
# File 'lib/chef/formatters/error_inspectors/api_error_formatting.rb', line 87 def format_rest_error Array(Chef::JSONCompat.from_json(exception.response.body)["error"]).join('; ') rescue Exception exception.response.body end |
#server_url ⇒ Object
101 102 103 |
# File 'lib/chef/formatters/error_inspectors/api_error_formatting.rb', line 101 def server_url config[:chef_server_url] end |
#username ⇒ Object
93 94 95 |
# File 'lib/chef/formatters/error_inspectors/api_error_formatting.rb', line 93 def username config[:node_name] end |