Gracefully handle bad ObjectId passed on URL

This commit is contained in:
Sybren A. Stüvel 2016-05-02 13:23:52 +02:00
parent 53aa0dae3b
commit 57375bd0c4

View File

@ -445,7 +445,10 @@ def stream_to_gcs(project_id):
uploaded_file = request.files['file'] uploaded_file = request.files['file']
projects = current_app.data.driver.db['projects'] projects = current_app.data.driver.db['projects']
try:
project = projects.find_one(ObjectId(project_id), projection={'_id': 1}) project = projects.find_one(ObjectId(project_id), projection={'_id': 1})
except InvalidId:
project = None
if not project: if not project:
raise NotFound('Project %s does not exist' % project_id) raise NotFound('Project %s does not exist' % project_id)