deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [2/7] git commit: Minor changes to filter_all and report_error to make sure errors (e.g. 401 authentication) are propagated back to client.
Date Wed, 29 Feb 2012 10:52:33 GMT
Minor changes to filter_all and report_error to make sure errors (e.g. 401 authentication)
are propagated back to client.


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

Branch: refs/heads/master
Commit: 865fdfae6166046c9a0e21aa124ce0af370ed0c7
Parents: ee99ac5
Author: marios <marios@redhat.com>
Authored: Tue Feb 28 17:52:19 2012 +0200
Committer: marios <marios@redhat.com>
Committed: Wed Feb 29 12:51:43 2012 +0200

----------------------------------------------------------------------
 .../lib/deltacloud/helpers/application_helper.rb   |   26 +++++++++-----
 1 files changed, 17 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/865fdfae/server/lib/deltacloud/helpers/application_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/application_helper.rb b/server/lib/deltacloud/helpers/application_helper.rb
index d44f108..b54ec41 100644
--- a/server/lib/deltacloud/helpers/application_helper.rb
+++ b/server/lib/deltacloud/helpers/application_helper.rb
@@ -76,15 +76,23 @@ module ApplicationHelper
       filter.merge!(:state => params[:state]) if params[:state]
       filter = {} if filter.keys.size.eql?(0)
       singular = model.to_s.singularize.to_sym
-      @benchmark = Benchmark.measure do
-        @elements = driver.send(model.to_sym, credentials, filter)
+      begin
+       @benchmark = Benchmark.measure do
+          @elements = driver.send(model.to_sym, credentials, filter)
+        end
+      rescue
+        @exception = $!
       end
-      headers['X-Backend-Runtime'] = @benchmark.real.to_s
-      instance_variable_set(:"@#{model}", @elements)
-      respond_to do |format|
-        format.html { haml :"#{model}/index" }
-        format.xml { haml :"#{model}/index" }
-        format.json { convert_to_json(singular, @elements) }
+      if @elements
+        headers['X-Backend-Runtime'] = @benchmark.real.to_s
+        instance_variable_set(:"@#{model}", @elements)
+        respond_to do |format|
+          format.html { haml :"#{model}/index" }
+          format.xml { haml :"#{model}/index" }
+          format.json { convert_to_json(singular, @elements) }
+        end
+      else
+        report_error(@exception.code)
       end
   end
 
@@ -106,7 +114,7 @@ module ApplicationHelper
   end
 
   def report_error(code=nil)
-    @error, @code = request.env['sinatra.error'], code
+    @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
     respond_to do |format|


Mime
View raw message