incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core] More verbose error handling for Deltacloud client
Date Thu, 15 Jul 2010 11:07:26 GMT
---
 client/lib/deltacloud.rb |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index de2b327..a3b59fb 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -296,16 +296,20 @@ module DeltaCloud
       if conf[:method].eql?(:post)
         RestClient.send(:post, conf[:path], conf[:form_data], default_headers) do |response,
request, &block|
           if response.respond_to?('body')
+            puts response_error(response.body) if response_errors?(response.body)
             yield response.body if block_given?
           else
+            puts response_error(response.to_s) if response_errors?(response.to_s)
             yield response.to_s if block_given?
           end
         end
       else
         RestClient.send(conf[:method], conf[:path], default_headers) do |response, request,
&block|
           if response.respond_to?('body')
+            puts response_error(response.body) if response_errors?(response.body)
             yield response.body if block_given?
           else
+            puts response_error(response.to_s) if response_errors?(response.to_s)
             yield response.to_s if block_given?
           end
         end
@@ -376,6 +380,20 @@ module DeltaCloud
       }
     end
 
+    def response_error(response)
+      error_msg = (Nokogiri::XML(response)/'/error')
+      unless error_msg.empty?
+        return "[ERROR] #{(error_msg/'message').text}"
+      else
+        return false
+      end
+    end
+
+    def response_errors?(response)
+      error_msg = (Nokogiri::XML(response)/'/error')
+      return true unless error_msg.empty?
+    end
+
   end
 
   class Documentation
-- 
1.7.1.1


Mime
View raw message