summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2013-08-08 16:42:09 +0200
committermguetlein <martin.guetlein@gmail.com>2013-08-08 16:42:09 +0200
commit174578c95c0997c0544b837ac89f2091efa2c5e3 (patch)
treef9b2a633c09d04c81433d4b6eb52daef589e07f3
parent84ac7a779bbe24c92fcb3863245ffcb6b57fb0b5 (diff)
error handling rewrite: making sure to pass backtrace
-rw-r--r--lib/opentox.rb27
1 files 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']