Skip to content

Commit

Permalink
Issue wurmlab#666 Work in progress
Browse files Browse the repository at this point in the history
422 exception handling
  • Loading branch information
gorsyan committed Dec 6, 2023
1 parent 95e331b commit 2ebd98e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ pkg
node_modules

spec/dotdir/*
spec/downloads/*
spec/downloads/*
lib/sequenceserver/routes.textClipping
2 changes: 1 addition & 1 deletion lib/sequenceserver/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def serializable_classes
# Fetches job with the given id.
def fetch(id)
job_file = File.join(DOTDIR, id, 'job.yaml')
fail NotFound unless File.exist?(job_file)
return nil unless File.exist?(job_file)

YAML.safe_load_file(
job_file,
Expand Down
5 changes: 5 additions & 0 deletions lib/sequenceserver/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class Routes < Sinatra::Base
# an empty body if the job hasn't finished yet.
get '/:jid.json' do |jid|
job = Job.fetch(jid)
halt 404, { error: "Job not found" }.to_json if job.nil?
halt 202 unless job.done?

report = Report.generate(job)
Expand Down Expand Up @@ -165,14 +166,17 @@ class Routes < Sinatra::Base
# Download BLAST report in various formats.
get '/download/:jid.:type' do |jid, type|
job = Job.fetch(jid)
halt 404, { error: "Job not found" }.to_json if job.nil?
out = BLAST::Formatter.new(job, type)
halt 404, { error: "File not found" }.to_json unless File.exist?(out.filepath)
send_file out.filepath, filename: out.filename, type: out.mime
end

post '/cloud_share' do
content_type :json
request_params = JSON.parse(request.body.read)
job = Job.fetch(request_params['job_id'])
halt 404, { error: "Job not found" }.to_json if job.nil?

unless job.done?
status 422
Expand Down Expand Up @@ -278,6 +282,7 @@ class Routes < Sinatra::Base
# Get the query sequences, selected databases, and advanced params used.
def update_searchdata_from_job(searchdata)
job = Job.fetch(params[:job_id])
return { error: "Job not found" }.to_json if job.nil?
return if job.imported_xml_file

# Only read job.qfile if we are not going to use Database.retrieve.
Expand Down

0 comments on commit 2ebd98e

Please sign in to comment.