diff --git a/storage_service/views/object_view.py b/storage_service/views/object_view.py index 6d54a3c..3faeb36 100644 --- a/storage_service/views/object_view.py +++ b/storage_service/views/object_view.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 from flask import jsonify, request, abort, current_app, Response from flask_classful import FlaskView -from minio.error import BucketAlreadyExists, BucketAlreadyOwnedByYou, ResponseError, NoSuchKey +from minio.error import BucketAlreadyExists, BucketAlreadyOwnedByYou, ResponseError, NoSuchKey, NoSuchBucket from marshmallow import ValidationError from utils import storage from schemas import DescriptionSchema @@ -16,6 +16,8 @@ class ObjectView(FlaskView): storage.connection.stat_object(current_app.config['MINIO_BUCKET_NAME'], tag) except NoSuchKey: return False + except NoSuchBucket: + return False return True @@ -26,10 +28,6 @@ class ObjectView(FlaskView): except ValidationError as e: abort(400, str(e)) - # check for conflict - if self._check_existance(description['tag']): - abort(409) - # get and validate file file = request.files['soundFile'] @@ -49,6 +47,10 @@ class ObjectView(FlaskView): pass # Everything else should be raised + # check for conflict + if self._check_existance(description['tag']): + abort(409) + # poot file into bucket try: storage.connection.put_object(current_app.config['MINIO_BUCKET_NAME'], description['tag'], file,