From c9498b7c1ce419cd534cb0f9005762561f2b33ec Mon Sep 17 00:00:00 2001 From: mguetlein Date: Fri, 9 Aug 2013 08:35:21 +0200 Subject: simplify setting of @accept variable (and set default to turtle instead of html), add html rendering for errors --- lib/opentox.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/opentox.rb b/lib/opentox.rb index cefe51f..aeea589 100644 --- a/lib/opentox.rb +++ b/lib/opentox.rb @@ -30,15 +30,14 @@ module OpenTox before do @uri = uri(request.env['PATH_INFO']) # prevent /algorithm/algorithm in algorithm service get_subjectid if respond_to? :get_subjectid - # fix IE - request.env['HTTP_ACCEPT'] += ";text/html" if request.env["HTTP_USER_AGENT"]=~/MSIE/ - request.env['HTTP_ACCEPT'] = request.params["media"] if request.params["media"] + + request.env['HTTP_ACCEPT'] += ";text/html" if request.env["HTTP_USER_AGENT"]=~/MSIE/ # fix for IE + request.env['HTTP_ACCEPT'] = request.params["media"] if request.params["media"] # allow to set accept type in url via ?media= + request.env['HTTP_ACCEPT'] = "text/turtle" if request.env['HTTP_ACCEPT'] =~ /\*\/\*/ #set default to turtle + @accept = request.env['HTTP_ACCEPT'] request.content_type ? response['Content-Type'] = request.content_type : response['Content-Type'] = request.env['HTTP_ACCEPT'] parse_input if request.request_method =~ /POST|PUT/ - @accept = request.env['HTTP_ACCEPT'] - @accept = "text/html" if @accept =~ /\*\/\*/ or request.env["HTTP_USER_AGENT"]=~/MSIE/ - @accept = request.params["media"] if request.params["media"] Authorization.check_policy(@uri) if env['REQUEST_METHOD'] == "PUT" && $aa[SERVICE.to_sym][:uri] && $aa[SERVICE.to_sym] response['Content-Type'] = @accept end @@ -102,8 +101,14 @@ module OpenTox # 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 + case @accept + when /text\/html/ + content_type "text/html" + halt ot_error.http_code, ot_error.to_turtle.to_html + else + content_type "text/turtle" + halt ot_error.http_code, ot_error.to_turtle + end end error Exception do # wraps non-opentox-errors like NoMethodError within an InternalServerError -- cgit v1.2.3