You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/04/27 13:07:59 UTC

[PATCH core 3/4] Added more detailed descriptions to error codes and more debugging output, like HTTP headers

From: Michal Fojtik <mf...@redhat.com>

Fixed special cases when no exception was throwed, just status code.
Improved wraping for backtrace in error pages.
---
 .../lib/deltacloud/helpers/application_helper.rb   |   16 ++++++--
 server/public/stylesheets/compiled/application.css |    8 ++++
 server/views/errors/400.html.haml                  |    9 ++++-
 server/views/errors/401.html.haml                  |    3 ++
 server/views/errors/403.html.haml                  |   12 ++++++-
 server/views/errors/404.html.haml                  |    9 ++++-
 server/views/errors/404.xml.haml                   |    2 +-
 server/views/errors/405.html.haml                  |   21 +++++++++++
 server/views/errors/405.xml.haml                   |    5 +++
 server/views/errors/500.html.haml                  |   37 ++++++++++++++++++++
 server/views/errors/500.xml.haml                   |    6 ++--
 server/views/errors/502.html.haml                  |    6 +++-
 12 files changed, 122 insertions(+), 12 deletions(-)
 create mode 100644 server/views/errors/405.html.haml
 create mode 100644 server/views/errors/405.xml.haml
 create mode 100644 server/views/errors/500.html.haml

diff --git a/server/lib/deltacloud/helpers/application_helper.rb b/server/lib/deltacloud/helpers/application_helper.rb
index ad1e7cb..d496368 100644
--- a/server/lib/deltacloud/helpers/application_helper.rb
+++ b/server/lib/deltacloud/helpers/application_helper.rb
@@ -105,11 +105,19 @@ module ApplicationHelper
   end
 
   def report_error(code=nil)
-    @error = request.env['sinatra.error']
-    response.status = code || @error.code
+    @error, @code = request.env['sinatra.error'], code
+    @code = 500 if not @code and not @error.class.method_defined? :code
+    if @error
+      unless @error.class.method_defined? :cause
+        @cause = nil
+      else
+        @cause = @error.cause
+      end
+    end
+    response.status = @code || @error.code
     respond_to do |format|
-      format.xml { haml :"errors/#{code || @error.code}", :layout => false }
-      format.html { haml :"errors/#{code || @error.code}", :layout => :error }
+      format.xml { haml :"errors/#{@code || @error.code}", :layout => false }
+      format.html { haml :"errors/#{@code || @error.code}", :layout => :error }
     end
   end
 
diff --git a/server/public/stylesheets/compiled/application.css b/server/public/stylesheets/compiled/application.css
index e354d41..78d3018 100644
--- a/server/public/stylesheets/compiled/application.css
+++ b/server/public/stylesheets/compiled/application.css
@@ -667,3 +667,11 @@ h3.description {
   font-size : 70%;
   color : #ccc;
 }
+
+pre {
+  white-space: pre-wrap; /* css-3 */
+  white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
+  white-space: -pre-wrap; /* Opera 4-6 */
+  white-space: -o-pre-wrap; /* Opera 7 */
+  word-wrap: break-word; /* Internet Explorer 5.5+ */
+}
diff --git a/server/views/errors/400.html.haml b/server/views/errors/400.html.haml
index 1d3ee48..0743859 100644
--- a/server/views/errors/400.html.haml
+++ b/server/views/errors/400.html.haml
@@ -1,4 +1,4 @@
-%h1 Validation Failure
+%h1 Bad Request
 
 %p= @error.message
 
@@ -9,3 +9,10 @@
   %di
     %dt Parameter
     %dd= @error.name
+  %di
+    %dt Status code
+    %dd= response.status
+  %di
+    %dt Explanation
+    %dd
+      The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
diff --git a/server/views/errors/401.html.haml b/server/views/errors/401.html.haml
index 1226587..ae1aab2 100644
--- a/server/views/errors/401.html.haml
+++ b/server/views/errors/401.html.haml
@@ -6,3 +6,6 @@
   %di
     %dt Request URL
     %dd= request.env['REQUEST_URI']
+  %di
+    %dt Status code
+    %dd= response.status
diff --git a/server/views/errors/403.html.haml b/server/views/errors/403.html.haml
index 59e9fe9..23229db 100644
--- a/server/views/errors/403.html.haml
+++ b/server/views/errors/403.html.haml
@@ -1,6 +1,16 @@
-%h1 Method Not Allowed
+%h1 Forbidden
 
 %dl
   %di
     %dt Request URL
     %dd= request.env['REQUEST_URI']
+  %di
+    %dt Cause
+    %dd= @cause
+  %di
+    %dt Status code
+    %dd= response.status
+  %di
+    %dt Explanation
+    %dd
+      The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server does not wish to make this information available to the client, the status code 404 (Not Found) can be used instead.
diff --git a/server/views/errors/404.html.haml b/server/views/errors/404.html.haml
index dfbb116..6dc6efc 100644
--- a/server/views/errors/404.html.haml
+++ b/server/views/errors/404.html.haml
@@ -1,6 +1,13 @@
-%h1 Not Found
+%h1 Resource not found
 
 %dl
   %di
     %dt Request URL
     %dd= request.env['REQUEST_URI']
+  %di
+    %dt Status code
+    %dd= response.status
+  %di
+    %dt Explanation
+    %dd
+      The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. 
diff --git a/server/views/errors/404.xml.haml b/server/views/errors/404.xml.haml
index 38840f3..47aede6 100644
--- a/server/views/errors/404.xml.haml
+++ b/server/views/errors/404.xml.haml
@@ -1,2 +1,2 @@
 %error{:url => "#{request.env['REQUEST_URI']}", :status => "#{response.status}"}
-  %message Not Found
+  %message Resource not found
diff --git a/server/views/errors/405.html.haml b/server/views/errors/405.html.haml
new file mode 100644
index 0000000..4227818
--- /dev/null
+++ b/server/views/errors/405.html.haml
@@ -0,0 +1,21 @@
+%h1 Method Not Allowed
+
+%p
+  A 405 status code is returned when the client has tried to use a request method that the server does not allow. Request methods that are allowed should be sent with the response (common request methods are POST and GET).
+
+%dl
+  %di
+    %dt Request URL
+    %dd= request.env['REQUEST_URI']
+  %di
+    %dt Request headers
+    %dd
+      %pre
+        =request.env.inspect
+  %di
+    %dt Status code
+    %dd= response.status
+  %di
+    %dt Explanation
+    %dd
+      The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource.
diff --git a/server/views/errors/405.xml.haml b/server/views/errors/405.xml.haml
new file mode 100644
index 0000000..e0198f5
--- /dev/null
+++ b/server/views/errors/405.xml.haml
@@ -0,0 +1,5 @@
+%error{:url => "#{request.env['REQUEST_URI']}", :status => "#{response.status}"}
+  %message
+    Requested method not allowed
+  %method
+    =request.env['REQUEST_METHOD']
diff --git a/server/views/errors/500.html.haml b/server/views/errors/500.html.haml
new file mode 100644
index 0000000..ec34ce2
--- /dev/null
+++ b/server/views/errors/500.html.haml
@@ -0,0 +1,37 @@
+%h1 Internal Server Error
+
+%p= "#{@error.class}: #{@error.message}"
+- if @error.class.method_defined? :details
+  %p= @error.details
+
+%dl
+  %di
+    %dt Request URL
+    %dd= request.env['REQUEST_URI']
+  %di
+    %dt Request headers
+    %dd
+      %pre
+        =request.env.inspect
+  %di
+    %dt Parameters
+    %dd
+      %pre
+        =params.inspect
+  %di
+    %dt Response headers
+    %dd
+      %pre
+        =response.headers.inspect
+  %di
+    %dt Code
+    %dd 500
+  %di
+    %dt Backtrace
+    %dd
+      %pre
+        =@error.backtrace.join("\n")
+  %di
+    %dt Explanation
+    %dd
+      The server encountered an unexpected condition which prevented it from fulfilling the request.
diff --git a/server/views/errors/500.xml.haml b/server/views/errors/500.xml.haml
index 87c8e19..b067212 100644
--- a/server/views/errors/500.xml.haml
+++ b/server/views/errors/500.xml.haml
@@ -1,8 +1,8 @@
 %error{:url => "#{request.env['REQUEST_URI']}", :status => "#{response.status}"}
   %kind backend_error
   %backend{ :driver => driver_symbol }
-    %code= @error.code
-    %cause= @error.cause
-    - if @error.details
+    %code=response.status
+    %cause= @cause
+    - if @error.class.method_defined? :details
       %details< #{cdata @error.details.join("\n")}
   %message< #{cdata @error.message}
diff --git a/server/views/errors/502.html.haml b/server/views/errors/502.html.haml
index b6b3e1b..31eac25 100644
--- a/server/views/errors/502.html.haml
+++ b/server/views/errors/502.html.haml
@@ -1,4 +1,4 @@
-%h1 Backend Error
+%h1 Backend provider error
 
 %p= @error.message
 
@@ -12,3 +12,7 @@
   %di
     %dt Code
     %dd= @error.code
+  %di
+    %dt Explanation
+    %dd
+      The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request.
-- 
1.7.4.1