Method: Chef::Formatters::ErrorInspectors::RegistrationErrorInspector#humanize_http_exception

Defined in:
lib/chef/formatters/error_inspectors/registration_error_inspector.rb

#humanize_http_exception(error_description) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/chef/formatters/error_inspectors/registration_error_inspector.rb', line 58

def humanize_http_exception(error_description)
  response = exception.response
  case response
  when Net::HTTPUnauthorized
    if clock_skew?
      error_description.section("Authentication Error:", <<~E)
        Failed to authenticate to the #{ChefUtils::Dist::Server::PRODUCT} (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 #{ChefUtils::Dist::Server::PRODUCT} (http 401).
      E

      error_description.section("Server Response:", format_rest_error)
      error_description.section("Relevant Config Settings:", <<~E)
        chef_server_url         "#{server_url}"
        validation_client_name  "#{username}"
        validation_key          "#{api_key}"

        If these settings are correct, your validation_key may be invalid.
      E
    end
  when Net::HTTPForbidden
    error_description.section("Authorization Error:", <<~E)
      Your validation client is not authorized to create the client for this node on the #{ChefUtils::Dist::Server::PRODUCT} (HTTP 403).
    E
    error_description.section("Possible Causes:", <<~E)
      * There may already be a client named "#{config[:node_name]}"
      * Your validation client (#{username}) may have misconfigured authorization permissions.
    E
  when Net::HTTPBadRequest
    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)
  when Net::HTTPNotFound
    error_description.section("Resource Not Found:", <<~E)
      The #{ChefUtils::Dist::Server::PRODUCT} returned a HTTP 404. This usually indicates that your chef_server_url configuration is incorrect.
    E
    error_description.section("Relevant Config Settings:", <<~E)
      chef_server_url "#{server_url}"
    E
  when Net::HTTPNotAcceptable
    describe_406_error(error_description, response)
  when Net::HTTPInternalServerError
    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)
  when Net::HTTPBadGateway, Net::HTTPServiceUnavailable
    error_description.section("Server Unavailable", "The #{ChefUtils::Dist::Server::PRODUCT} is temporarily unavailable")
    error_description.section("Server Response:", format_rest_error)
  else
    error_description.section("Unexpected API Request Failure:", format_rest_error)
  end
end