lib/onering/api.rb in onering-client-0.0.86 vs lib/onering/api.rb in onering-client-0.0.87

- old
+ new

@@ -121,21 +121,25 @@ options.get(:headers,[]).each do |name, value| next if name == 'Content-Type' and value == 'application/json' Onering::Logger.debug("+#{name}: #{value}", "Onering::API") end - case (method.to_sym rescue method) - when :post - rv = Onering::API.post(endpoint, options) - when :put - rv = Onering::API.put(endpoint, options) - when :delete - rv = Onering::API.delete(endpoint, options) - when :head - rv = Onering::API.head(endpoint, options) - else - rv = Onering::API.get(endpoint, options) + begin + case (method.to_sym rescue method) + when :post + rv = Onering::API.post(endpoint, options) + when :put + rv = Onering::API.put(endpoint, options) + when :delete + rv = Onering::API.delete(endpoint, options) + when :head + rv = Onering::API.head(endpoint, options) + else + rv = Onering::API.get(endpoint, options) + end + rescue SocketError => e + Onering::Logger.fatal!("Unable to connect to #{Onering::API.base_uri}", "Onering::API") end if rv.code >= 500 raise Errors::ServerError.new("HTTP #{rv.code} - #{Onering::Util.http_status(rv.code)} #{rv.parsed_response.get('error.message','') rescue ''}") elsif rv.code >= 400 @@ -284,10 +288,10 @@ if response.code < 400 and response.body File.open(keyfile, 'w').puts(response.body) raise Actions::Retry.new else # all errors are fatal at this stage - Onering::Logger.fatal("Cannot autoregister client: HTTP #{response.code} - #{(response.parsed_response || {}).get('error.message', 'Unknown error')}", "Onering::API") + Onering::Logger.fatal!("Cannot autoregister client: HTTP #{response.code} - #{(response.parsed_response || {}).get('error.message', 'Unknown error')}", "Onering::API") end end # it is an error to not have created a client.pem by now raise Errors::AuthenticationMissing.new("Cannot autoregister client: keyfile not created") \ No newline at end of file