diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2019-04-23 14:17:01 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2019-04-23 14:17:01 +0800 |
commit | af018993c1d4c1fd9ca3de90a5c4c860d96e72f7 (patch) | |
tree | 34d056ed70fac791101367b021a5ea03435ef919 | |
parent | aacae59d128707dea731664f4c164ef92330c4a9 (diff) |
Refactor codes for vnf pkg
Change-Id: I773ca4a01a0d543c624a0dca56505654e73c7ef3
Issue-ID: VFC-1306
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | catalog/packages/views/common.py | 7 | ||||
-rwxr-xr-x | catalog/packages/views/vnf_package_subscription_views.py | 24 | ||||
-rw-r--r-- | catalog/pub/exceptions.py | 4 |
3 files changed, 22 insertions, 13 deletions
diff --git a/catalog/packages/views/common.py b/catalog/packages/views/common.py index 43455c5c..d336ec1a 100644 --- a/catalog/packages/views/common.py +++ b/catalog/packages/views/common.py @@ -19,6 +19,7 @@ from rest_framework import status from rest_framework.response import Response from catalog.pub.exceptions import CatalogException +from catalog.pub.exceptions import BadRequestException from catalog.pub.exceptions import NsdmBadRequestException from catalog.pub.exceptions import PackageNotFoundException from catalog.pub.exceptions import ResourceNotFoundException @@ -87,6 +88,12 @@ def view_safe_call_with_log(logger): detail=e.message, status=status.HTTP_404_NOT_FOUND ) + except BadRequestException as e: + logger.error(e.message) + return make_error_resp( + detail=e.message, + status=status.HTTP_400_BAD_REQUEST + ) except NsdmBadRequestException as e: logger.error(e.message) return make_error_resp( diff --git a/catalog/packages/views/vnf_package_subscription_views.py b/catalog/packages/views/vnf_package_subscription_views.py index 303f0d40..32904e32 100755 --- a/catalog/packages/views/vnf_package_subscription_views.py +++ b/catalog/packages/views/vnf_package_subscription_views.py @@ -28,20 +28,19 @@ from catalog.packages.biz.vnf_pkg_subscription import QuerySubscription from catalog.packages.biz.vnf_pkg_subscription import TerminateSubscription from catalog.packages.views.common import validate_data from catalog.pub.exceptions import VnfPkgSubscriptionException +from catalog.pub.exceptions import BadRequestException from .common import view_safe_call_with_log logger = logging.getLogger(__name__) -VALID_FILTERS = ["callbackUri", "notificationTypes", "vnfdId", "vnfPkgId", "operationalState", "usageState"] - -def get_problem_details_serializer(status_code, error_message): - problem_details = { - "status": status_code, - "detail": error_message - } - problem_details_serializer = ProblemDetailsSerializer(data=problem_details) - problem_details_serializer.is_valid() - return problem_details_serializer +VALID_FILTERS = [ + "callbackUri", + "notificationTypes", + "vnfdId", + "vnfPkgId", + "operationalState", + "usageState" +] class CreateQuerySubscriptionView(APIView): @@ -74,9 +73,8 @@ class CreateQuerySubscriptionView(APIView): logger.debug("SubscribeNotification--get::> %s" % request.query_params) if request.query_params and not set(request.query_params).issubset(set(VALID_FILTERS)): - problem_details_serializer = get_problem_details_serializer(status.HTTP_400_BAD_REQUEST, - "Not a valid filter") - return Response(data=problem_details_serializer.data, status=status.HTTP_400_BAD_REQUEST) + raise BadRequestException("Not a valid filter") + resp_data = QuerySubscription().query_multi_subscriptions(request.query_params) subscriptions_serializer = PkgmSubscriptionsSerializer(data=resp_data) diff --git a/catalog/pub/exceptions.py b/catalog/pub/exceptions.py index a9354204..e0dac0e4 100644 --- a/catalog/pub/exceptions.py +++ b/catalog/pub/exceptions.py @@ -17,6 +17,10 @@ class CatalogException(Exception): pass +class BadRequestException(CatalogException): + pass + + class ResourceNotFoundException(CatalogException): pass |