Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Commit

Permalink
Merge pull request #102 from site5/bugfix/resolve_error
Browse files Browse the repository at this point in the history
Resolv host before checking WHM hash
  • Loading branch information
boone committed Aug 12, 2015
2 parents 864d7d0 + e77bf12 commit ea84209
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/lumberg/exceptions.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Lumberg
# WHM Exception for when an argument is invalid, missing, etc.
class WhmArgumentError < ArgumentError; end
# WHM Exception for when a connection fails
class WhmConnectionError < ArgumentError; end
# WHM Exception for when a request is performed on an invalid user
class WhmInvalidUser < RuntimeError; end
end
2 changes: 1 addition & 1 deletion lib/lumberg/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Lumberg
VERSION = '2.0.1'
VERSION = '3.0.0'
end
9 changes: 7 additions & 2 deletions lib/lumberg/whm/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ def initialize(options)
@ssl_verify ||= false
@ssl = options.delete(:ssl)
@host = options.delete(:host)
validate_server_host

@hash = format_hash(options.delete(:hash))
@user = (options.has_key?(:user) ? options.delete(:user) : 'root')
@basic_auth = options.delete(:basic_auth)
@timeout = options.delete(:timeout)
@whostmgr = options.delete(:whostmgr)

validate_server_host

@base_url = format_url(options)
end

Expand Down Expand Up @@ -257,6 +257,11 @@ def do_request(uri, function, params)
end.get(function).body
@force_response_type = nil
@response

rescue Faraday::Error::ConnectionFailed, Faraday::TimeoutError
raise Lumberg::WhmConnectionError.new(
"#{@host} is either unavailable or is not currently accepting requests. Please try again in a few minutes."
)
end

def format_query(hash)
Expand Down
16 changes: 15 additions & 1 deletion spec/whm/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,23 @@ module Lumberg
expect do
Whm::Server.new(host: "nxdomain.tld", hash: "")
end.to raise_error(
Lumberg::WhmArgumentError, "Unable to resolve nxdomain.tld"
Lumberg::WhmArgumentError, "Unable to resolve nxdomain.tld"
)
end

it "raises message for connection failed" do
VCR.turn_off!
stub_request(:get, "#{@url_base}/version").to_timeout

expect do
@whm = Whm::Server.new(@login)
@whm.version
end.to raise_error(
Lumberg::WhmConnectionError, "#{@login[:host]} is either unavailable or is not currently accepting requests. Please try again in a few minutes."
)

VCR.turn_on!
end
end

describe "setting timeout" do
Expand Down

0 comments on commit ea84209

Please sign in to comment.