lib/rest-client-wrapper.rb in lazar-1.1.3 vs lib/rest-client-wrapper.rb in lazar-1.2.0
- old
+ new
@@ -26,18 +26,18 @@
define_singleton_method method do |uri,payload={},headers={},waiting_task=nil|
uri = Addressable::URI.encode(uri)
# check input
- bad_request_error "Headers are not a hash: #{headers.inspect} for #{uri}." unless headers==nil or headers.is_a?(Hash)
+ raise ArgumentError, "Headers are not a hash: #{headers.inspect} for #{uri}." unless headers==nil or headers.is_a?(Hash)
headers[:subjectid] ||= @@subjectid
- bad_request_error "Invalid URI: '#{uri}'" unless URI.valid? uri
+ raise ArgumentError, "Invalid URI: '#{uri}'" unless URI.valid? uri
# make sure that no header parameters are set in the payload
[:accept,:content_type,:subjectid].each do |header|
if defined? $aa || URI(uri).host == URI($aa[:uri]).host
else
- bad_request_error "#{header} should be submitted in the headers of URI: #{uri}" if payload and payload.is_a?(Hash) and payload[header]
+ raise ArgumentError, "#{header} should be submitted in the headers of URI: #{uri}" if payload and payload.is_a?(Hash) and payload[header]
end
end
# create request
args={}
@@ -54,10 +54,11 @@
@request = RestClient::Request.new(args)
# ignore error codes from Task services (may return error codes >= 400 according to API, which causes exceptions in RestClient and RDF::Reader)
@response = @request.execute do |response, request, result|
if [301, 302, 307].include? response.code and request.method == :get
response.follow_redirection(request, result)
+=begin
elsif response.code >= 400 and !URI.task?(uri)
error = known_errors.collect{|e| e if e[:code] == response.code}.compact.first
begin # errors are returned as error reports in json, try to parse
content = JSON.parse(response)
msg = content["message"].to_s
@@ -66,17 +67,19 @@
rescue # parsing error failed, use complete content as message
msg = "Could not parse error response from rest call '#{method}' to '#{uri}':\n#{response}"
cause = nil
end
Object.method(error[:method]).call "#{msg}, #{uri}, #{cause}" # call error method
+=end
else
response
end
end
end
end
+=begin
#@return [Array] of hashes with error code, method and class
def self.known_errors
errors = []
RestClient::STATUSES.each do |code,k|
if code >= 400
@@ -86,8 +89,9 @@
errors << {:code => code, :method => method.to_sym, :class => klass}
end
end
errors
end
+=end
end
end