From 5c1340a7940e55dcf39fc854bcd82fe747d5a7c0 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 6 Jun 2011 16:54:56 +0000 Subject: halts (partially) substituted by OpenTox errors --- application.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/application.rb b/application.rb index 850e85f..5fbb749 100644 --- a/application.rb +++ b/application.rb @@ -71,7 +71,7 @@ end # @return [application/rdf+xml,application/x-yaml,text/uri-list] Task representation in requested format, Accept:text/uri-list returns URI of the created resource if task status is "Completed" get '/:id/?' do task = Task[params[:id]] - halt 404, "Task '#{params[:id]}' not found." unless task + raise OpenTox::NotFoundError.new "Task '#{params[:id]}' not found." unless task # set task http code according to status case task.hasStatus @@ -117,7 +117,7 @@ get '/:id/?' do halt code, task.uri end else - halt 400, "MIME type '"+request.env['HTTP_ACCEPT'].to_s+"' not supported, valid Accept-Headers are \"application/rdf+xml\" and \"application/x-yaml\"." + raise OpenTox::BadRequestError.new "MIME type '"+request.env['HTTP_ACCEPT'].to_s+"' not supported, valid Accept-Headers are \"application/rdf+xml\" and \"application/x-yaml\"." end end @@ -139,11 +139,11 @@ end get '/:id/:property/?' do response['Content-Type'] = 'text/plain' task = Task[params[:id]] - halt 404,"Task #{params[:id]} not found." unless task + raise OpenTox::NotFoundError.new"Task #{params[:id]} not found." unless task begin eval("task.#{params[:property]}").to_s rescue - halt 404,"Unknown task property #{params[:property]}." + raise OpenTox::NotFoundError.new"Unknown task property #{params[:property]}." end end @@ -185,7 +185,7 @@ end put '/:id/:hasStatus/?' do task = Task[params[:id]] - halt 404,"Task #{params[:id]} not found." unless task + raise OpenTox::NotFoundError.new"Task #{params[:id]} not found." unless task task.hasStatus = params[:hasStatus] unless /pid/ =~ params[:hasStatus] task.description = params[:description] if params[:description] # error report comes as yaml string @@ -202,7 +202,7 @@ put '/:id/:hasStatus/?' do when "pid" task.pid = params[:pid] when "Running" - halt 400,"Task cannot be set to running after not running anymore" if task.hasStatus!="Running" + raise OpenTox::BadRequestError.new"Task cannot be set to running after not running anymore" if task.hasStatus!="Running" task.waiting_for = params[:waiting_for] if params.has_key?("waiting_for") if params.has_key?("percentageCompleted") task.percentageCompleted = params[:percentageCompleted].to_f @@ -224,21 +224,21 @@ put '/:id/:hasStatus/?' do halt 402,"Invalid value for hasStatus: '"+params[:hasStatus].to_s+"'" end - halt 500,"could not save task" unless task.save + raise"could not save task" unless task.save end # Delete a task # @return [text/plain] Status message delete '/:id/?' do task = Task[params[:id]] - halt 404, "Task #{params[:id]} not found." unless task + raise OpenTox::NotFoundError.new "Task #{params[:id]} not found." unless task begin Process.kill(9,task.pid) unless task.pid.nil? task.delete response['Content-Type'] = 'text/plain' "Task #{params[:id]} deleted." rescue - halt 500,"Cannot kill task with pid #{task.pid}" + raise"Cannot kill task with pid #{task.pid}" end end -- cgit v1.2.3