handle file error using an exception
This commit is contained in:
parent
07e6f8e6ed
commit
602fb2d9cd
1 changed files with 5 additions and 5 deletions
|
@ -34,12 +34,12 @@ def download():
|
|||
form.start_time.data = datetime.now().replace(minute=0, second=0) - timedelta(hours=1)
|
||||
form.length.data = 60
|
||||
elif form.validate_on_submit():
|
||||
try:
|
||||
output_filename = prepare_download(form)
|
||||
if output_filename:
|
||||
flash('The download should start immediately.', 'success')
|
||||
return render_template('download.html', form=form, filename=output_filename)
|
||||
else:
|
||||
flash('Error preparing download!', 'warning')
|
||||
except ValueError as e:
|
||||
flash('Error preparing download: {}'.format(e), 'warning')
|
||||
else:
|
||||
flash('Error in form!', 'warning')
|
||||
return render_template('download.html', form=form)
|
||||
|
@ -79,7 +79,7 @@ def prepare_download(form):
|
|||
if source['start_time'] <= form.start_time.data < source['start_time'] + source['length']:
|
||||
start_index = i
|
||||
if start_index is None:
|
||||
return None
|
||||
raise ValueError('Could not find start file')
|
||||
sources = sources[start_index:]
|
||||
|
||||
# Seek into the first file
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue