diff --git a/app/services/http_json/responder.rb b/app/services/http_json/responder.rb index 5ccd56cdf..5774c918f 100644 --- a/app/services/http_json/responder.rb +++ b/app/services/http_json/responder.rb @@ -16,8 +16,6 @@ def initialize(requester, exception_class) def get(path, args) response = @requester.get(path, args) unpacked(response.body, path.to_s) - rescue => error - fail @exception_class, error.message end # - - - - - - - - - - - - - - - - - - - - - @@ -25,8 +23,6 @@ def get(path, args) def post(path, args) response = @requester.post(path, args) unpacked(response.body, path.to_s) - rescue => error - fail @exception_class, error.message end private @@ -34,13 +30,13 @@ def post(path, args) def unpacked(body, path) json = json_parse(body) unless json.is_a?(Hash) - fail error_msg(body, 'is not JSON Hash') + throw error_msg(body, 'is not JSON Hash') end if json.has_key?('exception') - fail JSON.pretty_generate(json['exception']) + throw JSON.pretty_generate(json['exception']) end unless json.has_key?(path) - fail error_msg(body, "has no key for '#{path}'") + throw error_msg(body, "has no key for '#{path}'") end json[path] end @@ -50,7 +46,7 @@ def unpacked(body, path) def json_parse(body) JSON.parse(body) rescue JSON::ParserError - fail error_msg(body, 'is not JSON') + throw error_msg(body, 'is not JSON') end # - - - - - - - - - - - - - - - - - - - - - @@ -59,6 +55,12 @@ def error_msg(body, text) "http response.body #{text}:#{body}" end + # - - - - - - - - - - - - - - - - - - - - - + + def throw(message) + fail @exception_class, message + end + end end