handle file error using an exception

stable
neingeist 6 years ago
parent 07e6f8e6ed
commit 602fb2d9cd

@ -34,12 +34,12 @@ def download():
form.start_time.data = datetime.now().replace(minute=0, second=0) - timedelta(hours=1) form.start_time.data = datetime.now().replace(minute=0, second=0) - timedelta(hours=1)
form.length.data = 60 form.length.data = 60
elif form.validate_on_submit(): elif form.validate_on_submit():
try:
output_filename = prepare_download(form) output_filename = prepare_download(form)
if output_filename:
flash('The download should start immediately.', 'success') flash('The download should start immediately.', 'success')
return render_template('download.html', form=form, filename=output_filename) return render_template('download.html', form=form, filename=output_filename)
else: except ValueError as e:
flash('Error preparing download!', 'warning') flash('Error preparing download: {}'.format(e), 'warning')
else: else:
flash('Error in form!', 'warning') flash('Error in form!', 'warning')
return render_template('download.html', form=form) 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']: if source['start_time'] <= form.start_time.data < source['start_time'] + source['length']:
start_index = i start_index = i
if start_index is None: if start_index is None:
return None raise ValueError('Could not find start file')
sources = sources[start_index:] sources = sources[start_index:]
# Seek into the first file # Seek into the first file

Loading…
Cancel
Save