deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 1/2] RHEV-M: Raise 400 (Bad Request) when no API_PROVIDER is set
Date Mon, 05 Mar 2012 13:39:51 GMT
From: Michal Fojtik <mfojtik@redhat.com>

Previously Deltacloud API respond with code 500, related to
the 'split' method used to divide API_PROVIDER to URL and
Datacenter when started without our with empty API_PROVIDER.
With this patch, this error is properly captured and reported
as 400 (Bad Request). Appropriate error XML and message is provided
to the client.

Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb   |    5 +++--
 server/views/errors/401.html.haml                  |   13 +++++++------
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index 10ffef3..0d4e63f 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -205,8 +205,9 @@ class RHEVMDriver < Deltacloud::BaseDriver
   private
 
   def new_client(credentials)
-    url, datacenter = api_provider.split(';')
     safely do
+      raise 'No API provider set for this request.' unless api_provider
+      url, datacenter = api_provider.split(';')
       OVIRT::Client.new(credentials.user, credentials.password, url, datacenter)
     end
   end
@@ -327,7 +328,7 @@ class RHEVMDriver < Deltacloud::BaseDriver
 
   exceptions do
 
-    on /Bad Request/ do
+    on /(Bad Request|No API provider set)/ do
       status 400
     end
 
diff --git a/server/views/errors/401.html.haml b/server/views/errors/401.html.haml
index 1a135f9..c1d946b 100644
--- a/server/views/errors/401.html.haml
+++ b/server/views/errors/401.html.haml
@@ -2,7 +2,7 @@
   %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' =>
'e'}
     %li{ :'data-role' => 'list-divider'} Server message
     %li
-      %h3=[@error.class.name, @error.message].join(' - ')
+      %h3 Unauthorized
     %li{ :'data-role' => 'list-divider'} Original request URI
     %li
       %a{ :href => request.env['REQUEST_URI'], :'data-ajax' => 'false'}
@@ -15,11 +15,12 @@
       - else
         %em No details
 
-  %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
-    %h3 Backtrace
-    %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
-      %li
-        %pre=@error.backtrace.join("\n")
+  - if @error.respond_to :backtrace
+    %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
+      %h3 Backtrace
+      %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
+        %li
+          %pre=@error.backtrace.join("\n")
 
   %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
     %h3 Parameters
-- 
1.7.9.1


Mime
View raw message