You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2012/02/28 17:10:54 UTC
[PATCH 6/7] Minor changes to filter_all and report_error to make sure errors (e.g. 401 authentication) are propagated back to client.
From: marios <ma...@redhat.com>
Signed-off-by: marios <ma...@redhat.com>
---
.../lib/deltacloud/helpers/application_helper.rb | 26 +++++++++++++-------
1 files changed, 17 insertions(+), 9 deletions(-)
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|
--
1.7.6.5