deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1235273 - in /deltacloud/trunk: client/lib/deltacloud.rb server/views/errors/500.xml.haml
Date Tue, 24 Jan 2012 14:42:12 GMT
Author: mfojtik
Date: Tue Jan 24 14:42:12 2012
New Revision: 1235273

URL: http://svn.apache.org/viewvc?rev=1235273&view=rev
Log:
Client: Ruby client should now forward backtrace from the server to client

Signed-off-by: Michal fojtik <mfojtik@redhat.com>

Modified:
    deltacloud/trunk/client/lib/deltacloud.rb
    deltacloud/trunk/server/views/errors/500.xml.haml

Modified: deltacloud/trunk/client/lib/deltacloud.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/client/lib/deltacloud.rb?rev=1235273&r1=1235272&r2=1235273&view=diff
==============================================================================
--- deltacloud/trunk/client/lib/deltacloud.rb (original)
+++ deltacloud/trunk/client/lib/deltacloud.rb Tue Jan 24 14:42:12 2012
@@ -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 [500, 502].include? response.code
+          handle_backend_error(response) if [500, 502, 501].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 [500, 502].include? response.code
+          handle_backend_error(response) if [500, 502, 501].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')
@@ -392,16 +392,20 @@ module DeltaCloud
     # Re-raise backend errors as on exception in client with message from
     # backend
     class BackendError < StandardError
+
       def initialize(opts={})
-        @message = "[#{opts[:code]}] #{opts[:message]}"
-      end
-      def message
-        @message
+        super("#{opts[:code]} : #{opts[:message]}")
+        set_backtrace(opts[:backtrace].split("\n").map { |l| l.strip }[0..10]) if opts[:backtrace]
       end
+
     end
 
     def handle_backend_error(response)
-      raise BackendError.new(:message => (Nokogiri::XML(response)/'error/message').text,
:code => response.code)
+      response_xml = Nokogiri::XML(response)
+      backtrace = (response_xml/'error/backtrace').empty? ? nil : (response_xml/'error/backtrace').text
+      raise BackendError.new(:message => (response_xml/'error/message').text,
+                             :code => response.code,
+                             :backtrace => backtrace)
     end
 
     # Check if specified collection have wanted feature

Modified: deltacloud/trunk/server/views/errors/500.xml.haml
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/views/errors/500.xml.haml?rev=1235273&r1=1235272&r2=1235273&view=diff
==============================================================================
--- deltacloud/trunk/server/views/errors/500.xml.haml (original)
+++ deltacloud/trunk/server/views/errors/500.xml.haml Tue Jan 24 14:42:12 2012
@@ -3,10 +3,9 @@
   %backend{ :driver => driver_symbol, :provider => "#{Thread::current[:provider] ||
ENV['API_PROVIDER'] || 'default'}" }
     %code=response.status
   %message< #{cdata @error.message}
+  - if @error.respond_to? :backtrace
+    %backtrace=cdata @error.backtrace.join("\n")
   - if params
     %request
       - params.each do |k, v|
         %param{ :name => k}=v
-  - if @error.respond_to? :backtrace
-    %backtrace=@error.backtrace.join("\n")
-



Mime
View raw message