summaryrefslogtreecommitdiff
path: root/lib/chef/server_api.rb
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-03-12 12:36:14 -0700
committerGitHub <noreply@github.com>2018-03-12 12:36:14 -0700
commit797fe20ea3b529a36dc6a88e6101d3544b9ecb70 (patch)
tree23213fffe8302dda586746fc2c16412bfc3193b0 /lib/chef/server_api.rb
parentde0ed26e4b0a42f3af827912339ecae65253b52b (diff)
parent2e94dd8d733b9bae92228f4eca2dcdb0c58594c3 (diff)
downloadchef-797fe20ea3b529a36dc6a88e6101d3544b9ecb70.tar.gz
Merge pull request #6253 from jeunito/feat/5556
Knife should give a useful error when the chef_server_url isn't a chef server API
Diffstat (limited to 'lib/chef/server_api.rb')
-rw-r--r--lib/chef/server_api.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/chef/server_api.rb b/lib/chef/server_api.rb
index c501544954..d539ed5fed 100644
--- a/lib/chef/server_api.rb
+++ b/lib/chef/server_api.rb
@@ -25,6 +25,7 @@ require "chef/http/json_output"
require "chef/http/remote_request_id"
require "chef/http/validate_content_length"
require "chef/http/api_versions"
+require "ffi_yajl"
class Chef
class ServerAPI < Chef::HTTP
@@ -57,6 +58,21 @@ class Chef
alias :post_rest :post
alias :put_rest :put
+ def get(path, headers = {})
+ request(:GET, path, headers)
+ rescue Net::HTTPServerException => e
+ if e.response.kind_of?(Net::HTTPNotFound)
+ begin
+ FFI_Yajl::Parser.parse(e.response.body)
+ rescue FFI_Yajl::ParseError => e
+ raise Chef::Exceptions::NotAChefServerException
+ end
+ raise
+ else
+ raise
+ end
+ end
+
# Makes an HTTP request to +path+ with the given +method+, +headers+, and
# +data+ (if applicable). Does not apply any middleware, besides that
# needed for Authentication.