From 878f014ec6cc808af99af5045bcc1a1143cab8d9 Mon Sep 17 00:00:00 2001 From: gebele Date: Thu, 5 Jul 2018 10:38:55 +0000 Subject: updated with endpoint list; refined error handling; refined prediction input --- application.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index ebcb0af..a5f9ff2 100644 --- a/application.rb +++ b/application.rb @@ -7,6 +7,7 @@ include OpenTox "api.rb", "compound.rb", "dataset.rb", + "endpoint.rb", "feature.rb", "model.rb", "nanoparticle.rb", @@ -28,12 +29,13 @@ configure :development do end before do - paths = [ + $paths = [ "/", "aa", "api", "compound", "dataset", + "endpoint", "feature", "model", "nanoparticle", @@ -41,7 +43,7 @@ before do "substance", "swagger", "validation"] - if request.path == "/" || paths.include?(request.path.split("/")[1]) + if request.path == "/" || $paths.include?(request.path.split("/")[1]) @accept = request.env['HTTP_ACCEPT'] response['Content-Type'] = @accept else @@ -54,8 +56,14 @@ not_found do end error do - @error = request.env['sinatra.error'] - haml :error + if request.path == "/" || $paths.include?(request.path.split("/")[1]) + @accept = request.env['HTTP_ACCEPT'] + response['Content-Type'] = @accept + @accept == "text/plain" ? request.env['sinatra.error'] : request.env['sinatra.error'].to_json + else + @error = request.env['sinatra.error'] + haml :error + end end # https://github.com/britg/sinatra-cross_origin#responding-to-options -- cgit v1.2.3