(#13) Raise exception when required params are missing

Instead of doing a system exit and printing to stderr, raise an
exception if parameters are missing when attempting to make an http
connection.
This commit is contained in:
Brian Cain 2015-11-15 13:33:21 -08:00
parent 3394a14ea0
commit c1689da3c4

View file

@ -3,8 +3,7 @@ require 'faraday'
class Http class Http
def self.get_conn(verbose, url) def self.get_conn(verbose, url)
if url.nil? if url.nil?
STDERR.puts "The url you provided was empty" raise "Did not provide a url to connect to"
exit 1
end end
conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday| conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
@ -18,13 +17,11 @@ class Http
def self.get_conn_with_auth(verbose, url, user, password) def self.get_conn_with_auth(verbose, url, user, password)
if url.nil? if url.nil?
STDERR.puts "The url you provided was empty" raise "Did not provide a url to connect to"
exit 1
end end
if user.nil? if user.nil?
STDERR.puts "You did not provide a user to authenticate with" raise "You did not provide a user to authenticate with"
exit 1
end end
conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday| conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|