summaryrefslogtreecommitdiff
path: root/lib/chef/api_client.rb
diff options
context:
space:
mode:
authortylercloke <tylercloke@gmail.com>2015-06-04 12:23:55 -0700
committertylercloke <tylercloke@gmail.com>2015-06-05 13:47:44 -0700
commit58048d42caeadc290876a02aaec7eec6f305920a (patch)
treeea9743fc860b69f2c4c20bb26b7f58a5d2f6f44f /lib/chef/api_client.rb
parent4f2400c8cce57e68f14cb9d4b756ab82b23dd69d (diff)
downloadchef-58048d42caeadc290876a02aaec7eec6f305920a.tar.gz
Better API version error handling helper code.
Renamed Chef::Mixin::ApiVersionRequestHandling.handle_version_http_exception -> server_client_api_version_intersection and made it do much more useful / sane things. See comments for details.
Diffstat (limited to 'lib/chef/api_client.rb')
-rw-r--r--lib/chef/api_client.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/chef/api_client.rb b/lib/chef/api_client.rb
index 3b777b3574..ad31fb7d7b 100644
--- a/lib/chef/api_client.rb
+++ b/lib/chef/api_client.rb
@@ -32,7 +32,7 @@ class Chef
include Chef::Mixin::FromFile
include Chef::Mixin::ParamsValidate
- include Chef::ApiVersionRequestHandling
+ include Chef::Mixin::ApiVersionRequestHandling
SUPPORTED_API_VERSIONS = [0,1]
@@ -272,7 +272,8 @@ class Chef
new_client = chef_rest_v1.put("clients/#{name}", payload)
rescue Net::HTTPServerException => e
# rescue API V0 if 406 and the server supports V0
- raise e unless handle_version_http_exception(e, SUPPORTED_API_VERSIONS[0], SUPPORTED_API_VERSIONS[-1])
+ supported_versions = server_client_api_version_intersection(e, SUPPORTED_API_VERSIONS)
+ raise e unless supported_versions && supported_versions.include?(0)
new_client = chef_rest_v0.put("clients/#{name}", payload)
end
@@ -308,7 +309,8 @@ class Chef
rescue Net::HTTPServerException => e
# rescue API V0 if 406 and the server supports V0
- raise e unless handle_version_http_exception(e, SUPPORTED_API_VERSIONS[0], SUPPORTED_API_VERSIONS[-1])
+ supported_versions = server_client_api_version_intersection(e, SUPPORTED_API_VERSIONS)
+ raise e unless supported_versions && supported_versions.include?(0)
# under API V0, a key pair will always be created unless public_key is
# passed on initial POST