From 174578c95c0997c0544b837ac89f2091efa2c5e3 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Thu, 8 Aug 2013 16:42:09 +0200 Subject: error handling rewrite: making sure to pass backtrace --- lib/opentox.rb | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/opentox.rb b/lib/opentox.rb index ea29832..cefe51f 100644 --- a/lib/opentox.rb +++ b/lib/opentox.rb @@ -98,22 +98,23 @@ module OpenTox end end end - - # Attention: Error within tasks are catched by Task.run - error do + + + # ERROR HANDLING (for errors outside of tasks, errors inside of tasks are taken care of in Task.run) + def return_ot_error(ot_error) + content_type "text/turtle" + halt ot_error.http_code, ot_error.to_turtle + end + + error Exception do # wraps non-opentox-errors like NoMethodError within an InternalServerError error = request.env['sinatra.error'] - if error.respond_to? :report - body = error.report.to_turtle - else - response['Content-Type'] = "text/plain" - body = "#{error.message}\n" - body += "URI: #{error.uri}\n" if error.is_a?(RuntimeError) - body += error.backtrace.join("\n") - end - error.respond_to?(:http_code) ? code = error.http_code : code = 500 - halt code, body + return_ot_error(OpenTox::Error.new(500,error.message,nil,error.backtrace)) end + error OpenTox::Error do # this covers all opentox errors + return_ot_error(request.env['sinatra.error']) + end + def return_task( task ) raise "http_code == nil" unless task.code!=nil case request.env['HTTP_ACCEPT'] -- cgit v1.2.3