deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvl...@redhat.com
Subject [PATCH] DTACLOUD-379 - omit backtrace using 505
Date Wed, 05 Dec 2012 13:56:09 GMT
From: Joe VLcek <jvlcek@redhat.com>

---
 server/lib/deltacloud/drivers/exceptions.rb        |  8 ++++
 .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb   |  4 ++
 server/lib/deltacloud/helpers/deltacloud_helper.rb |  1 +
 server/views/errors/505.html.haml                  | 47 ++++++++++++++++++++++
 server/views/errors/505.xml.haml                   | 13 ++++++
 5 files changed, 73 insertions(+)
 create mode 100644 server/views/errors/505.html.haml
 create mode 100644 server/views/errors/505.xml.haml

diff --git a/server/lib/deltacloud/drivers/exceptions.rb b/server/lib/deltacloud/drivers/exceptions.rb
index 7bbf510..59b1291 100644
--- a/server/lib/deltacloud/drivers/exceptions.rb
+++ b/server/lib/deltacloud/drivers/exceptions.rb
@@ -93,6 +93,13 @@ module Deltacloud
       end
     end
 
+    class ActionNotAllowed < DeltacloudException
+      def initialize(e, message=nil)
+        message ||= e.message
+        super(505, e.class.name, message, nil)
+      end
+    end
+
     class NotImplemented < DeltacloudException
       def initialize(e, message)
         message ||= e.message
@@ -161,6 +168,7 @@ module Deltacloud
           when 501 then NotImplemented.new(e, @message)
           when 502 then ProviderError.new(e, @message)
           when 504 then ProviderTimeout.new(e, @message)
+          when 505 then ActionNotAllowed.new(e, @message)
         end
       end
 
diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index 37e6622..835736f 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -342,6 +342,10 @@ class RhevmDriver < Deltacloud::BaseDriver
       status 404
     end
 
+    on /Cannot delete Template. Template is being used/ do
+      status 505
+    end
+
     on /(RestClient|RHEVM|OVIRT)/ do
       status 500
     end
diff --git a/server/lib/deltacloud/helpers/deltacloud_helper.rb b/server/lib/deltacloud/helpers/deltacloud_helper.rb
index 34519c0..e26a94c 100644
--- a/server/lib/deltacloud/helpers/deltacloud_helper.rb
+++ b/server/lib/deltacloud/helpers/deltacloud_helper.rb
@@ -248,6 +248,7 @@ module Deltacloud::Helpers
       when 500; { :message => "Internal Server Error" }
       when 502; { :message => "Backend Server Error" }
       when 504; { :message => "Gateway Timeout" }
+      when 505; { :message => "Action Not Allowed" }
       when 501; { :message => "Not Supported" }
       end
     end
diff --git a/server/views/errors/505.html.haml b/server/views/errors/505.html.haml
new file mode 100644
index 0000000..8cd3c74
--- /dev/null
+++ b/server/views/errors/505.html.haml
@@ -0,0 +1,47 @@
+%div{ :'data-role' => :content, :'data-theme' => 'b'}
+  %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' =>
'e'}
+    %li{ :'data-role' => 'list-divider'} Server message
+    %li
+      %h3= h [@error.class.name, @error.message].join(' - ')
+    %li{ :'data-role' => 'list-divider'} Original request URI
+    %li
+      %a{ :href => request.env['REQUEST_URI'], :'data-ajax' => 'false'}
+        %span=request.env['REQUEST_URI']
+        %span{ :class => 'ui-li-count'} Retry
+    %li{ :'data-role' => 'list-divider'} Error details
+    %li
+      - if @error.class.method_defined? :details
+        %p= h @error.details
+      - else
+        %em No details
+    %li{ :'data-role' => 'list-divider'} Backtrace
+    %li
+      %pre= bt @error.backtrace
+
+  - if @error.backtrace
+    %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
+      %h3 Backtrace
+      %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
+        %li
+          %pre= h @error.backtrace.join("\n")
+
+  %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
+    %h3 Parameters
+    %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
+      - if params.keys.empty?
+        %li{ :'data-role' => 'list-divider'} No parameters
+      - params.each do |key, value|
+        - next if value.inspect.to_s == '#'
+        %li{ :'data-role' => 'list-divider'}=key
+        %li
+          %span{:style => 'font-weight:normal;'}=value.inspect
+
+
+  %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
+    %h3 Request details
+    %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
+      - request.env.each do |key, value|
+        - next if value.inspect.to_s == '#'
+        %li{ :'data-role' => 'list-divider'}=key
+        %li
+          %span{:style => 'font-weight:normal;'}= h value.inspect
diff --git a/server/views/errors/505.xml.haml b/server/views/errors/505.xml.haml
new file mode 100644
index 0000000..b3e71e2
--- /dev/null
+++ b/server/views/errors/505.xml.haml
@@ -0,0 +1,13 @@
+- unless defined?(partial)
+  !!! XML
+%error{:url => "#{request.env['REQUEST_URI']}", :status => "#{response.status}"}
+  %kind backend_error
+  %backend{ :driver => driver_symbol, :provider => "#{Thread::current[:provider] ||
ENV['API_PROVIDER'] || 'default'}" }
+    %code=response.status
+  %message< #{cdata @error.message}
+  - if @error.respond_to?(:backtrace) and !@error.backtrace.nil?
+    %backtrace=cdata(@error.backtrace.join("\n"))
+  - if params
+    %request
+      - params.each do |k, v|
+        %param{ :name => k}=v
-- 
1.7.11.7


Mime
View raw message