summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2017-08-09 10:45:14 +0000
committergebele <gebele@in-silico.ch>2017-08-09 10:45:14 +0000
commit51de592286b0132080b95f3e443a7c5f0eeb9581 (patch)
treeb370607e445fc33e390593ab73a37dd4e8c7e474
parent8775a27a2bd41e16efb1cc627f915977a10916bb (diff)
consistent error handling
-rw-r--r--application.rb27
1 files changed, 6 insertions, 21 deletions
diff --git a/application.rb b/application.rb
index 1409ac1..e3ccba4 100644
--- a/application.rb
+++ b/application.rb
@@ -13,15 +13,6 @@ configure :development do
enable :reloader
end
-helpers do
- class Numeric
- def percent_of(n)
- self.to_f / n.to_f * 100.0
- end
- end
-
-end
-
before do
@version = File.read("VERSION").chomp
end
@@ -89,8 +80,7 @@ post '/predict/?' do
# process batch prediction
if !params[:fileselect].blank?
if params[:fileselect][:filename] !~ /\.csv$/
- @error = "Please submit a csv file."
- return haml :error
+ bad_request_error "Please submit a csv file."
end
File.open('tmp/' + params[:fileselect][:filename], "w") do |f|
f.write(params[:fileselect][:tempfile].read)
@@ -101,18 +91,16 @@ post '/predict/?' do
if input.class == OpenTox::Dataset
dataset = OpenTox::Dataset.find input
else
- @error = "Could not serialize file '#{@filename}' ."
- return haml :error
+ bad_request_error "Could not serialize file '#{@filename}'."
end
rescue
- @error = "Could not serialize file '#{@filename}' ."
- return haml :error
+ bad_request_error "Could not serialize file '#{@filename}'."
end
@compounds = dataset.compounds
if @compounds.size == 0
- @error = dataset[:warnings]
+ message = dataset[:warnings]
dataset.delete
- return haml :error
+ bad_request_error message
end
# for csv export
@@ -249,10 +237,7 @@ post '/predict/?' do
$logger.debug "input:#{@identifier}"
# get compound from SMILES
@compound = Compound.from_smiles @identifier
- if @compound.blank?
- @error = "'#{@identifier}' is not a valid SMILES string."
- return haml :error
- end
+ bad_request_error "'#{@identifier}' is not a valid SMILES string." if @compound.blank?
@models = []
@predictions = []