From 81f0924c654875a738b646ad951a28f906e0a97c Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 18 Jul 2012 09:59:21 +0200 Subject: rest call error handling fixed --- lib/rest-client-wrapper.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'lib/rest-client-wrapper.rb') 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 -- cgit v1.2.3