Gracefully handle bad ObjectId passed on URL

This commit is contained in:
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']
projects = current_app.data.driver.db['projects']
project = projects.find_one(ObjectId(project_id), projection={'_id': 1})
try:
project = projects.find_one(ObjectId(project_id), projection={'_id': 1})
except InvalidId:
project = None
if not project:
raise NotFound('Project %s does not exist' % project_id)