incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1181725 - /incubator/deltacloud/trunk/client/lib/deltacloud.rb
Date Tue, 11 Oct 2011 11:39:09 GMT
Author: mfojtik
Date: Tue Oct 11 11:39:08 2011
New Revision: 1181725

URL: http://svn.apache.org/viewvc?rev=1181725&view=rev
Log:
Client: Added error handler for 502 code

Modified:
    incubator/deltacloud/trunk/client/lib/deltacloud.rb

Modified: incubator/deltacloud/trunk/client/lib/deltacloud.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/lib/deltacloud.rb?rev=1181725&r1=1181724&r2=1181725&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client/lib/deltacloud.rb (original)
+++ incubator/deltacloud/trunk/client/lib/deltacloud.rb Tue Oct 11 11:39:08 2011
@@ -359,7 +359,7 @@ module DeltaCloud
       if conf[:method].eql?(:post)
         resource = RestClient::Resource.new(conf[:path], :open_timeout => conf[:open_timeout],
:timeout => conf[:timeout])
         resource.send(:post, conf[:form_data], default_headers.merge(extended_headers)) do
|response, request, block|
-          handle_backend_error(response) if response.code.eql?(500)
+          handle_backend_error(response) if [500, 502].include? response.code
           if response.respond_to?('body')
             yield response.body if block_given?
           else
@@ -369,7 +369,7 @@ module DeltaCloud
       else
         resource = RestClient::Resource.new(conf[:path], :open_timeout => conf[:open_timeout],
:timeout => conf[:timeout])
         resource.send(conf[:method], default_headers.merge(extended_headers)) do |response,
request, block|
-          handle_backend_error(response) if response.code.eql?(500)
+          handle_backend_error(response) if [500, 502].include? response.code
           if conf[:method].eql?(:get) and [301, 302, 307].include? response.code
             response.follow_redirection(request) do |response, request, block|
               if response.respond_to?('body')
@@ -393,7 +393,7 @@ module DeltaCloud
     # backend
     class BackendError < StandardError
       def initialize(opts={})
-        @message = opts[:message]
+        @message = "[#{opts[:code]}] #{opts[:message]}"
       end
       def message
         @message
@@ -401,7 +401,7 @@ module DeltaCloud
     end
 
     def handle_backend_error(response)
-      raise BackendError.new(:message => (Nokogiri::XML(response)/'error/message').text)
+      raise BackendError.new(:message => (Nokogiri::XML(response)/'error/message').text,
:code => response.code)
     end
 
     # Check if specified collection have wanted feature



Mime
View raw message