Code Review
/
modeling
/
etsicatalog.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
return 404 instead of 500 if subscription does not exist
[modeling/etsicatalog.git]
/
catalog
/
packages
/
views
/
common.py
diff --git
a/catalog/packages/views/common.py
b/catalog/packages/views/common.py
index
6285cb9
..
12840a5
100644
(file)
--- a/
catalog/packages/views/common.py
+++ b/
catalog/packages/views/common.py
@@
-18,7
+18,7
@@
import logging
from rest_framework import status
from rest_framework.response import Response
from rest_framework import status
from rest_framework.response import Response
-from catalog.pub.exceptions import CatalogException
+from catalog.pub.exceptions import CatalogException
, SubscriptionDoesNotExistsException
from catalog.pub.exceptions import BadRequestException
from catalog.pub.exceptions import NsdmBadRequestException
from catalog.pub.exceptions import PackageNotFoundException
from catalog.pub.exceptions import BadRequestException
from catalog.pub.exceptions import NsdmBadRequestException
from catalog.pub.exceptions import PackageNotFoundException
@@
-39,6
+39,14
@@
def validate_data(data, serializer):
return serialized_data
return serialized_data
+def validate_req_data(data, serializer):
+ serialized_data = serializer(data=data)
+ if not serialized_data.is_valid():
+ logger.error('Data validation failed.')
+ raise BadRequestException(serialized_data.errors)
+ return serialized_data
+
+
def fmt_error_rsp(error_message, status):
return {"errorMessage": error_message, "error": status}
def fmt_error_rsp(error_message, status):
return {"errorMessage": error_message, "error": status}
@@
-100,6
+108,12
@@
def view_safe_call_with_log(logger):
detail=e.args[0],
status=status.HTTP_400_BAD_REQUEST
)
detail=e.args[0],
status=status.HTTP_400_BAD_REQUEST
)
+ except SubscriptionDoesNotExistsException as e:
+ logger.error(e.args[0])
+ return make_error_resp(
+ detail=e.args[0],
+ status=status.HTTP_404_NOT_FOUND
+ )
except VnfPkgSubscriptionException as e:
logger.error(e.args[0])
return make_error_resp(
except VnfPkgSubscriptionException as e:
logger.error(e.args[0])
return make_error_resp(
@@
-119,5
+133,7
@@
def view_safe_call_with_log(logger):
detail='Unexpected exception',
status=status.HTTP_500_INTERNAL_SERVER_ERROR
)
detail='Unexpected exception',
status=status.HTTP_500_INTERNAL_SERVER_ERROR
)
+
return wrapper
return wrapper
+
return view_safe_call
return view_safe_call