summaryrefslogtreecommitdiff
path: root/lib/rest-client-wrapper.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2012-07-18 09:59:21 +0200
committerChristoph Helma <helma@in-silico.ch>2012-07-18 09:59:21 +0200
commit81f0924c654875a738b646ad951a28f906e0a97c (patch)
tree9a879d0c28bf126248a60c25248ea8ebcffc6f2f /lib/rest-client-wrapper.rb
parent76144341d800cec80cbb063b8c1acf6da19fad5d (diff)
rest call error handling fixed
Diffstat (limited to 'lib/rest-client-wrapper.rb')
-rw-r--r--lib/rest-client-wrapper.rb24
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/rest-client-wrapper.rb b/lib/rest-client-wrapper.rb
index 5707831..e89c90d 100644
--- a/lib/rest-client-wrapper.rb
+++ b/lib/rest-client-wrapper.rb
@@ -42,8 +42,30 @@ module OpenTox
@response = @request.execute do |response, request, result|
if [301, 302, 307].include? response.code and request.method == :get
response.follow_redirection(request, result)
+ elsif response.code >= 400 and !URI.task?(uri)
+ message = response.to_s
+ message += "\nREST paramenters:\n#{request.args.inspect}"
+ case response.code
+ when 400
+ bad_request_error message, uri
+ when 401
+ not_authorized_error message, uri
+ when 404
+ not_found_error message, uri
+ when 433
+ locked_error message, uri
+ when 500
+ internal_server_error message, uri
+ when 501
+ not_implemented_error message, uri
+ when 503
+ service_unavailable_error message, uri
+ when 504
+ time_out_error message, uri
+ else
+ rest_call_error message, uri
+ end
else
- raise OpenTox::RestCallError.new response.to_s, request, uri unless response.code < 400 or URI.task? uri
response
end
end