lib/nsisam/client.rb in nsisam-0.3.3 vs lib/nsisam/client.rb in nsisam-0.3.4
- old
+ new
@@ -1,8 +1,8 @@
require "json"
require "net/http"
-require "digest/sha512"
+require "digest"
require File.dirname(__FILE__) + '/errors'
module NSISam
class Client
@@ -102,16 +102,21 @@
request.basic_auth @user, @password
request
end
def execute_request(request)
- response = Net::HTTP.start @url, @port do |http|
- http.request(request)
+ begin
+ response = Net::HTTP.start @url, @port do |http|
+ http.request(request)
+ end
+ rescue Errno::ECONNREFUSED => e
+ raise NSISam::Errors::Client::ConnectionRefusedError
+ else
+ raise NSISam::Errors::Client::KeyNotFoundError if response.code == "404"
+ raise NSISam::Errors::Client::MalformedRequestError if response.code == "400"
+ raise NSISam::Errors::Client::AuthenticationError if response.code == "401"
+ JSON.parse(response.body)
end
- raise NSISam::Errors::Client::KeyNotFoundError if response.code == "404"
- raise NSISam::Errors::Client::MalformedRequestError if response.code == "400"
- raise NSISam::Errors::Client::AuthenticationError if response.code == "401"
- JSON.parse(response.body)
end
def verify_checksum(data, expected_checksum)
sha512_checksum = Digest::SHA512.hexdigest(data)
raise NSISam::Errors::Client::ChecksumMismatchError unless sha512_checksum == expected_checksum