deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core] Core: Make exceptions in console shorter (DTACLOUD-333)
Date Thu, 04 Oct 2012 11:45:37 GMT
From: Michal Fojtik <mfojtik@redhat.com>

* Fixed 100+ lines exceptions in console
* Use ExceptionHandler to log exceptions
* Fix case when exception is raised in CIMI and client
  use 'text/html' media type (browsers...)

Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/cimi/collections/base.rb                |    5 ++---
 server/lib/cimi/server.rb                          |    4 ++++
 server/lib/deltacloud/collections/base.rb          |    4 +---
 server/lib/deltacloud/helpers/deltacloud_helper.rb |   16 +++++++++++++++-
 4 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/server/lib/cimi/collections/base.rb b/server/lib/cimi/collections/base.rb
index ed61d17..c1fad3d 100644
--- a/server/lib/cimi/collections/base.rb
+++ b/server/lib/cimi/collections/base.rb
@@ -30,10 +30,9 @@ module CIMI::Collections
 
     register Rack::RespondTo
 
-    enable :xhtml
-    enable :dump_errors
-    enable :show_errors
+    enable :method_override
     disable :show_exceptions
+    disable :dump_errors
 
     set :config, Deltacloud[:cimi]
     set :root_url, config.root_url
diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index 86aaf3c..f0445f8 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -43,6 +43,10 @@ module CIMI
     include CIMI::Collections
     include CIMI::Model
 
+    enable :method_override
+    disable :show_exceptions
+    disable :dump_errors
+
     helpers Sinatra::Rabbit::URLFor(CIMI.collections)
 
     get '/' do
diff --git a/server/lib/deltacloud/collections/base.rb b/server/lib/deltacloud/collections/base.rb
index d5182ca..203b558 100644
--- a/server/lib/deltacloud/collections/base.rb
+++ b/server/lib/deltacloud/collections/base.rb
@@ -25,11 +25,9 @@ module Deltacloud::Collections
     helpers Sinatra::Rabbit::URLHelper
     register Rack::RespondTo
 
-    enable :xhtml
-    enable :dump_errors
-    enable :show_errors
     enable :method_override
     disable :show_exceptions
+    disable :dump_errors
 
     set :config, Deltacloud[:deltacloud]
     set :root_url, config.root_url
diff --git a/server/lib/deltacloud/helpers/deltacloud_helper.rb b/server/lib/deltacloud/helpers/deltacloud_helper.rb
index 36205e4..69d74a3 100644
--- a/server/lib/deltacloud/helpers/deltacloud_helper.rb
+++ b/server/lib/deltacloud/helpers/deltacloud_helper.rb
@@ -89,10 +89,24 @@ module Deltacloud::Helpers
       @error, @code = (request.env['sinatra.error'] || @exception), code
       @code = 500 if not @code and not @error.class.method_defined? :code
       response.status = @code || @error.code
+      log = Deltacloud::ExceptionHandler.logger
+      message = @error.respond_to?(:message) ? @error.message : translate_error_code(@code)
+      backtrace = (@error.respond_to?(:backtrace) and !@error.backtrace.nil?) ?
+        "\n\n#{@error.backtrace[0..10].join("\n")}\n\n" : ''
+      log.error "[#{@code}] #{[@error.class.to_s, message].join(':')}#{backtrace}"
       respond_to do |format|
         format.xml {  haml :"errors/#{@code || @error.code}", :layout => false }
         format.json { xml_to_json("errors/#{@code || @error.code}") }
-        format.html { haml :"errors/#{@code || @error.code}", :layout => :error }
+        format.html {
+          begin
+            haml :"errors/#{@code || @error.code}", :layout => :error
+          rescue RuntimeError
+            # If the HTML representation of error is missing, then try to report
+            # it through XML
+            @media_type=:xml
+            haml :"errors/#{@code || @error.code}", :layout => false
+          end
+        }
       end
     end
 
-- 
1.7.10.2


Mime
View raw message