Commit 54564437 authored by John E. Vincent's avatar John E. Vincent

A little 404 and exception handling

parent e79226c3
......@@ -26,13 +26,40 @@ namespace "/h" do
end
get '/:hostname/?' do |hostname|
host(:name => hostname).to_json
begin
h = host(:name => hostname)
if h.nil?
status 404
r = {"result" => "failure","error" => "Host not found"}
r.to_json
else
status 200
h.to_json
end
rescue Exception => e
status 500
r = {"result" => "failure","error" => "#{e.message}"}
r.to_json
end
end
get '/?' do
begin
hosts.map {|h| h.to_hash}
if hosts.size == 0
status 200
r = {"result" => "success", "response" => "No hosts found"}
r.to_json
else
status 200
hosts.to_json
end
rescue Exception => e
status 500
r = {"result" => "failure","error" => "#{e.message}"}
r.to_json
end
end
put '/?' do
begin
......@@ -82,13 +109,28 @@ end
namespace "/s" do
get '/:servicename/:hostname/?' do |servicename, hostname|
host_service(hostname, servicename).to_json
begin
hs = host_service(hostname, servicename)
status 200
hs.to_json
rescue Exception => e
status 500
r = {"result" => "failure", "error" => "#{e.message}"}
r.to_json
end
end
get '/:servicename/?' do |servicename|
begin
s = services(:name => servicename)
s.map {|x| x.to_hash}
status 200
s.to_json
rescue Exception => e
status 500
r = {"result" => "failure", "error" => "#{e.message}"}
r.to_json
end
end
get '/?' do
......@@ -107,9 +149,22 @@ namespace "/a" do
end
get '/:appname/?' do
begin
app = Application.find(:name => params[:appname]).first
if app.nil?
status 404
r = {"result" => "failure","error" => "Application not found"}
r.to_json
else
status 200
"#{app.to_json}"
end
rescue Exception => e
status 500
r = {"result" => "failure","error" => "#{e.message}"}
r.to_json
end
end
put '/:appname/?' do
begin
......@@ -136,16 +191,16 @@ namespace "/a" do
delete '/:appname/?' do
begin
app = Application.find(:name => params[:appname]).first
if app
if app.nil?
status 404
r = {"result" => "failure","error" => "Application not found"}
r.to_json
else
Configuration.find(:application_id => app.id).sort.each {|x| x.delete} if app.configurations.size > 0
app.delete
status 200
r = {"result" => "success", "id" => "#{app.id}"}
r.to_json
else
status 404
r = {"result" => "failure","error" => "Application not found"}
r.to_json
end
rescue Exception => e
status 500
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment