deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject git commit: Core: Make exceptions in console shorter (DTACLOUD-333)
Date Thu, 04 Oct 2012 17:25:24 GMT
Updated Branches:
  refs/heads/master 633b9b958 -> ae7a11b93


Core: Make exceptions in console shorter (DTACLOUD-333)

* 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>
TrackedAt: http://tracker.deltacloud.org/patch/a39d42cd708fb922feeed368e6de93cd2617ac93


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/ae7a11b9
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/ae7a11b9
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/ae7a11b9

Branch: refs/heads/master
Commit: ae7a11b93488d1d894888a7def75f585d5b67c18
Parents: 633b9b9
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Thu Oct 4 13:36:46 2012 +0200
Committer: David Lutterkort <lutter@redhat.com>
Committed: Thu Oct 4 10:25:13 2012 -0700

----------------------------------------------------------------------
 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(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ae7a11b9/server/lib/cimi/collections/base.rb
----------------------------------------------------------------------
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

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ae7a11b9/server/lib/cimi/server.rb
----------------------------------------------------------------------
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

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ae7a11b9/server/lib/deltacloud/collections/base.rb
----------------------------------------------------------------------
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

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ae7a11b9/server/lib/deltacloud/helpers/deltacloud_helper.rb
----------------------------------------------------------------------
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
 


Mime
View raw message