incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r963964 - in /incubator/deltacloud/trunk/server: lib/deltacloud/helpers/application_helper.rb server.rb views/errors/not_found.html.haml views/errors/not_found.xml.haml
Date Wed, 14 Jul 2010 08:06:50 GMT
Author: mfojtik
Date: Wed Jul 14 08:06:50 2010
New Revision: 963964

URL: http://svn.apache.org/viewvc?rev=963964&view=rev
Log:
Added not_found error handling for non-existing resources

Added:
    incubator/deltacloud/trunk/server/views/errors/not_found.html.haml
    incubator/deltacloud/trunk/server/views/errors/not_found.xml.haml
Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb
    incubator/deltacloud/trunk/server/server.rb

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb?rev=963964&r1=963963&r2=963964&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb Wed Jul
14 08:06:50 2010
@@ -74,10 +74,14 @@ module ApplicationHelper
   def show(model)
     @element = driver.send(model, credentials, { :id => params[:id]} )
     instance_variable_set("@#{model}", @element)
-    respond_to do |format|
-      format.html { haml :"#{model.to_s.pluralize}/show" }
-      format.xml { haml :"#{model.to_s.pluralize}/show" }
-      format.json { convert_to_json(model, @element) }
+    if @element
+      respond_to do |format|
+        format.html { haml :"#{model.to_s.pluralize}/show" }
+        format.xml { haml :"#{model.to_s.pluralize}/show" }
+        format.json { convert_to_json(model, @element) }
+      end
+    else
+        report_error(404, 'not_found')
     end
   end
 

Modified: incubator/deltacloud/trunk/server/server.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/server.rb?rev=963964&r1=963963&r2=963964&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/server.rb (original)
+++ incubator/deltacloud/trunk/server/server.rb Wed Jul 14 08:06:50 2010
@@ -1,7 +1,7 @@
+require 'sinatra'
 require 'deltacloud'
 require 'drivers'
 require 'json'
-require 'sinatra'
 require 'sinatra/respond_to'
 require 'sinatra/static_assets'
 require 'sinatra/rabbit'
@@ -255,10 +255,14 @@ END
     param :id,          :string,    :required
     control do
       @profile =  driver.hardware_profile(credentials, params[:id])
-      respond_to do |format|
-        format.xml { haml :'hardware_profiles/show', :layout => false }
-        format.html { haml :'hardware_profiles/show' }
-        format.json { convert_to_json(:hardware_profile, @profile) }
+      if @profile
+        respond_to do |format|
+          format.xml { haml :'hardware_profiles/show', :layout => false }
+          format.html { haml :'hardware_profiles/show' }
+          format.json { convert_to_json(:hardware_profile, @profile) }
+        end
+      else
+        report_error(404, 'not_found')
       end
     end
   end

Added: incubator/deltacloud/trunk/server/views/errors/not_found.html.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/errors/not_found.html.haml?rev=963964&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/views/errors/not_found.html.haml (added)
+++ incubator/deltacloud/trunk/server/views/errors/not_found.html.haml Wed Jul 14 08:06:50
2010
@@ -0,0 +1,6 @@
+%h1 Not Found
+
+%dl
+  %di
+    %dt Request URL
+    %dd= request.env['REQUEST_URI']

Added: incubator/deltacloud/trunk/server/views/errors/not_found.xml.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/errors/not_found.xml.haml?rev=963964&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/views/errors/not_found.xml.haml (added)
+++ incubator/deltacloud/trunk/server/views/errors/not_found.xml.haml Wed Jul 14 08:06:50
2010
@@ -0,0 +1,2 @@
+%error{:url => "#{request.env['REQUEST_URI']}", :status => "#{response.status}"}
+  %message Not Found



Mime
View raw message