lib/libis/services/rest_client.rb in libis-services-0.1.7 vs lib/libis/services/rest_client.rb in libis-services-0.1.9

- old
+ new

@@ -16,39 +16,69 @@ end def get(path, params = {}, headers = {}, &block) response = client[path].get({params: params}.merge headers, &block) parse_result response, &block - rescue ::RestClient::Exception => e + rescue ::RestClient::ServerBrokeConnection, IOError, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE => e + unless (tries ||= 0) > 3; sleep(5 ** tries); tries += 1; retry; end return {error_type: e.class.name, error_name: e.message, response: parse_result(e.response, &block)} + rescue Net::ReadTimeout, Timeout::Error => e + unless (tries ||= 0) > 1; sleep(5 ** tries); tries += 1; retry; end + return {error_type: e.class.name, error_name: e.message, response: parse_result(e.response, &block)} + rescue Exception => e + return {error_type: e.class.name, error_name: e.message, response: nil} end def post_url(path, params = {}, headers = {}, &block) response = client[path].post({params: params}.merge headers, &block) parse_result response, &block - rescue ::RestClient::Exception => e + rescue ::RestClient::ServerBrokeConnection, IOError, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE => e + unless (tries ||= 0) > 3; sleep(5 ** tries); tries += 1; retry; end return {error_type: e.class.name, error_name: e.message, response: parse_result(e.response, &block)} + rescue Net::ReadTimeout, Timeout::Error => e + unless (tries ||= 0) > 1; sleep(5 ** tries); tries += 1; retry; end + return {error_type: e.class.name, error_name: e.message, response: parse_result(e.response, &block)} + rescue Exception => e + return {error_type: e.class.name, error_name: e.message, response: nil} end def post_data(path, payload, headers = {}, &block) response = client[path].post(payload, headers, &block) parse_result response, &block - rescue ::RestClient::Exception => e + rescue ::RestClient::ServerBrokeConnection, IOError, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE => e + unless (tries ||= 0) > 3; sleep(5 ** tries); tries += 1; retry; end return {error_type: e.class.name, error_name: e.message, response: parse_result(e.response, &block)} + rescue Net::ReadTimeout, Timeout::Error => e + unless (tries ||= 0) > 1; sleep(5 ** tries); tries += 1; retry; end + return {error_type: e.class.name, error_name: e.message, response: parse_result(e.response, &block)} + rescue Exception => e + return {error_type: e.class.name, error_name: e.message, response: nil} end def put_url(path, params = {}, headers = {}, &block) response = client[path].put({params: params}.merge headers, &block) parse_result response, &block - rescue ::RestClient::Exception => e + rescue ::RestClient::ServerBrokeConnection, IOError, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE => e + unless (tries ||= 0) > 3; sleep(5 ** tries); tries += 1; retry; end return {error_type: e.class.name, error_name: e.message, response: parse_result(e.response, &block)} + rescue Net::ReadTimeout, Timeout::Error => e + unless (tries ||= 0) > 1; sleep(5 ** tries); tries += 1; retry; end + return {error_type: e.class.name, error_name: e.message, response: parse_result(e.response, &block)} + rescue Exception => e + return {error_type: e.class.name, error_name: e.message, response: nil} end def put_data(path, payload, headers = {}, &block) response = client[path].put(payload, headers, &block) parse_result response, &block - rescue ::RestClient::Exception => e + rescue ::RestClient::ServerBrokeConnection, IOError, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE => e + unless (tries ||= 0) > 3; sleep(5 ** tries); tries += 1; retry; end return {error_type: e.class.name, error_name: e.message, response: parse_result(e.response, &block)} + rescue Net::ReadTimeout, Timeout::Error => e + unless (tries ||= 0) > 1; sleep(5 ** tries); tries += 1; retry; end + return {error_type: e.class.name, error_name: e.message, response: parse_result(e.response, &block)} + rescue Exception => e + return {error_type: e.class.name, error_name: e.message, response: nil} end protected def parse_result(response)