From: Peter Amstutz Date: Mon, 12 Jan 2015 15:33:36 +0000 (-0500) Subject: 4924: Rename HTTPResponse to ArvadosAPIError. Use NET::HTTP Response titles X-Git-Tag: 1.1.0~1888^2~2 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/5fa38c36644bd122b8c31601aa864f05bf4fba73?hp=198963abf16d86d809a6a9fde36bc9ffd74685fd 4924: Rename HTTPResponse to ArvadosAPIError. Use NET::HTTP Response titles for error codes if no other error is available. --- diff --git a/sdk/cli/bin/arv b/sdk/cli/bin/arv index 0ecfb65147..f27711f41a 100755 --- a/sdk/cli/bin/arv +++ b/sdk/cli/bin/arv @@ -222,8 +222,8 @@ def edit_and_commit_object initial_obj, tmp_stem, global_opts, &block this_error = "YAML error parsing your input: #{e}" elsif e.is_a? JSON::ParserError this_error = "JSON error parsing your input: #{e}" - elsif e.is_a? HttpResponse - this_error = "API responded with error #{e.status}" + elsif e.is_a? ArvadosAPIError + this_error = "API responded with error #{e}" else this_error = "#{e.class}: #{e}" can_retry = false @@ -256,11 +256,7 @@ def edit_and_commit_object initial_obj, tmp_stem, global_opts, &block nil end -class HttpResponse < RuntimeError - attr_reader :status - def initialize status - @status = status - end +class ArvadosAPIError < RuntimeError end def check_response result @@ -271,7 +267,10 @@ def check_response result end if result.response.status != 200 - raise HttpResponse.new "#{result.response.status}: " + (results['errors'] && results['errors'].join('\n') || "") + require 'net/http' + raise ArvadosAPIError.new("#{result.response.status}: #{ + ((results['errors'] && results['errors'].join('\n')) || + Net::HTTPResponse::CODE_TO_OBJ[status.to_s].to_s.sub(/^Net::HTTP/, '')).titleize}") end results