Skip to content
Snippets Groups Projects
Commit fc8f7cc2 authored by Anthony Martin's avatar Anthony Martin
Browse files

move raise_error_response into base_client, call from http_client so it's...

move raise_error_response into base_client, call from http_client so it's closer to the error origin #6
parent 58c66e46
No related branches found
No related tags found
No related merge requests found
......@@ -149,19 +149,6 @@ module Steem
@@signatures[url][rpc_method_name] ||= Api::jsonrpc(url).get_signature(method: rpc_method_name).result
end
# @private
def raise_error_response(rpc_method_name, rpc_args, response)
raise UnknownError, "#{rpc_method_name}: #{response}" if response.error.nil?
error = response.error
if error.message == 'Invalid Request'
raise Steem::ArgumentError, "Unexpected arguments: #{rpc_args.inspect}. Expected: #{rpc_method_name} (#{args_keys_to_s(rpc_method_name)})"
end
BaseError.build_error(error, rpc_method_name)
end
# @private
def respond_to_missing?(m, include_private = false)
methods.nil? ? false : methods.include?(m.to_sym)
......@@ -203,14 +190,6 @@ module Steem
response = rpc_client.rpc_execute(@api_name, m, rpc_args)
if defined?(response.error) && !!response.error
if !!response.error.message
raise_error_response rpc_method_name, rpc_args, response
else
raise Steem::ArgumentError, response.error.inspect
end
end
if !!block
case response
when Hashie::Mash then yield response.result, response.error, response.id
......
......@@ -161,6 +161,19 @@ module Steem
sleep @backoff
end
# @private
def raise_error_response(rpc_method_name, rpc_args, response)
raise UnknownError, "#{rpc_method_name}: #{response}" if response.error.nil?
error = response.error
if error.message == 'Invalid Request'
raise Steem::ArgumentError, "Unexpected arguments: #{rpc_args.inspect}. Expected: #{rpc_method_name} (#{args_keys_to_s(rpc_method_name)})"
end
BaseError.build_error(error, rpc_method_name)
end
end
end
end
......@@ -17,7 +17,7 @@ module Steem
#
# @private
TIMEOUT_ERRORS = [Net::OpenTimeout, JSON::ParserError, Net::ReadTimeout,
Errno::EBADF, IOError, Errno::ENETDOWN]
Errno::EBADF, IOError, Errno::ENETDOWN, Steem::RemoteDatabaseLockError]
# @private
POST_HEADERS = {
......@@ -108,6 +108,22 @@ module Steem
else; response
end
[response].flatten.each_with_index do |r, i|
if defined?(r.error) && !!r.error
if !!r.error.message
begin
rpc_method_name = "#{api_name}.#{api_method}"
rpc_args = [request_object].flatten[i]
raise_error_response rpc_method_name, rpc_args, r
rescue *TIMEOUT_ERRORS => e
throw retry_timeout(:tota_cera_pila, e)
end
else
raise Steem::ArgumentError, r.error.inspect
end
end
end
yield_response response, &block
when '504' # Gateway Timeout
throw retry_timeout(:tota_cera_pila, response.body)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment