From: Michal Fojtik <[email protected]>

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 <[email protected]>
---
 .../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
-        %[email protected]("\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
+          %[email protected]("\n")
 
   %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
     %h3 Parameters
-- 
1.7.9.1

Reply via email to