diff --git a/cloudkitty/rating/hash/controllers/mapping.py b/cloudkitty/rating/hash/controllers/mapping.py index b98ef5b9..c1a074d1 100644 --- a/cloudkitty/rating/hash/controllers/mapping.py +++ b/cloudkitty/rating/hash/controllers/mapping.py @@ -158,6 +158,8 @@ class HashMapMappingsController(rating.RatingRestControllerBase): group_id=mapping.group_id, tenant_id=mapping.tenant_id) pecan.response.headers['Location'] = pecan.request.path + except db_api.MappingAlreadyExists as e: + pecan.abort(409, six.text_type(e)) except db_api.NoSuchMapping as e: pecan.abort(404, six.text_type(e)) except db_api.ClientHashMapError as e: diff --git a/cloudkitty/rating/hash/controllers/threshold.py b/cloudkitty/rating/hash/controllers/threshold.py index c7369923..ce53cb23 100644 --- a/cloudkitty/rating/hash/controllers/threshold.py +++ b/cloudkitty/rating/hash/controllers/threshold.py @@ -158,6 +158,8 @@ class HashMapThresholdsController(rating.RatingRestControllerBase): group_id=threshold.group_id, tenant_id=threshold.tenant_id) pecan.response.headers['Location'] = pecan.request.path + except db_api.ThresholdAlreadyExists as e: + pecan.abort(409, six.text_type(e)) except db_api.NoSuchThreshold as e: pecan.abort(404, six.text_type(e)) except db_api.ClientHashMapError as e: diff --git a/cloudkitty/rating/hash/db/sqlalchemy/api.py b/cloudkitty/rating/hash/db/sqlalchemy/api.py index ee24ce69..a0ed0a8c 100644 --- a/cloudkitty/rating/hash/db/sqlalchemy/api.py +++ b/cloudkitty/rating/hash/db/sqlalchemy/api.py @@ -432,6 +432,14 @@ class HashMap(api.HashMap): else: raise api.ClientHashMapError('No attribute to update.') return mapping_db + except exception.DBDuplicateEntry: + puuid = uuid + ptype = 'Mapping_id' + raise api.MappingAlreadyExists( + value, + puuid, + ptype, + tenant_id=kwargs.get('tenant_id')) except sqlalchemy.orm.exc.NoResultFound: raise api.NoSuchMapping(uuid) @@ -465,6 +473,14 @@ class HashMap(api.HashMap): else: raise api.ClientHashMapError('No attribute to update.') return threshold_db + except exception.DBDuplicateEntry: + puuid = uuid + ptype = 'Threshold_id' + raise api.ThresholdAlreadyExists( + value, + puuid, + ptype, + tenant_id=kwargs.get('tenant_id')) except sqlalchemy.orm.exc.NoResultFound: raise api.NoSuchThreshold(uuid)