---
.../lib/deltacloud/helpers/application_helper.rb | 12 ++++++++----
server/server.rb | 14 +++++++++-----
server/views/errors/not_found.html.haml | 6 ++++++
server/views/errors/not_found.xml.haml | 2 ++
4 files changed, 25 insertions(+), 9 deletions(-)
create mode 100644 server/views/errors/not_found.html.haml
create mode 100644 server/views/errors/not_found.xml.haml
diff --git a/server/lib/deltacloud/helpers/application_helper.rb
b/server/lib/deltacloud/helpers/application_helper.rb
index b8c4df7..94396d2 100644
--- a/server/lib/deltacloud/helpers/application_helper.rb
+++ b/server/lib/deltacloud/helpers/application_helper.rb
@@ -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
diff --git a/server/server.rb b/server/server.rb
index a8dc3d4..2516d3e 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -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
diff --git a/server/views/errors/not_found.html.haml
b/server/views/errors/not_found.html.haml
new file mode 100644
index 0000000..dfbb116
--- /dev/null
+++ b/server/views/errors/not_found.html.haml
@@ -0,0 +1,6 @@
+%h1 Not Found
+
+%dl
+ %di
+ %dt Request URL
+ %dd= request.env['REQUEST_URI']
diff --git a/server/views/errors/not_found.xml.haml
b/server/views/errors/not_found.xml.haml
new file mode 100644
index 0000000..38840f3
--- /dev/null
+++ b/server/views/errors/not_found.xml.haml
@@ -0,0 +1,2 @@
+%error{:url => "#{request.env['REQUEST_URI']}", :status =>
"#{response.status}"}
+ %message Not Found
--
1.7.1.1