Skip to content

Commit

Permalink
Merge pull request #253 from ael-code/add-volume-cleanup
Browse files Browse the repository at this point in the history
Handle exception and fix missing return
  • Loading branch information
ael-code committed Mar 5, 2016
2 parents 600d5fa + 97eb68b commit 4cf57cb
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions webant/webant.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def upload():

for requiredField in requiredFields:
if requiredField not in request.form:
renderErrorPage(gettext("Required field '%(mField)s' is missing",
mField=requiredField), 400)
return renderErrorPage(gettext("Required field '%(mField)s' is missing",
mField=requiredField), 400)
else:
body[requiredField] = request.form[requiredField]

Expand All @@ -155,10 +155,15 @@ def upload():

attachments.append(fileInfo)

addedVolumeID = app.archivant.insert_volume(body, attachments=attachments)
# remove temp files
for a in attachments:
os.remove(a['file'])
try:
addedVolumeID = app.archivant.insert_volume(body, attachments=attachments)
except Exception as e:
app.logger.exception(e)
return renderErrorPage(str(e), 500)
finally:
# remove temp files
for a in attachments:
os.remove(a['file'])
return redirect(url_for('view_volume', volumeID=addedVolumeID))

@app.route('/add', methods=['GET'])
Expand Down

0 comments on commit 4cf57cb

Please sign in to comment.