Add error handling for ocloud route
[pti/o2.git] / o2ims / views / ocloud_route.py
index 2490d4a..19613f0 100644 (file)
@@ -17,6 +17,7 @@ from flask_restx import Resource, reqparse
 
 from o2common.service.messagebus import MessageBus
 from o2common.views.pagination_route import link_header, PAGE_PARAM
+from o2common.views.route import ProblemDetails
 from o2ims.views import ocloud_view
 from o2ims.views.api_ns import api_ims_inventory as api_ims_inventory_v1
 from o2ims.views.ocloud_dto import OcloudDTO, ResourceTypeDTO,\
@@ -81,8 +82,9 @@ class OcloudsListRouter(Resource):
         res = ocloud_view.oclouds(bus.uow)
         if len(res) > 0:
             return res[0]
-        api_ims_inventory_v1.abort(
-            404, "oCloud doesn't exist")
+        ProblemDetails(
+            api_ims_inventory_v1,
+            404, "oCloud doesn't exist").abort()
 
 
 # ----------  ResourceTypes ---------- #
@@ -167,8 +169,10 @@ class ResourceTypeGetRouter(Resource):
         result = ocloud_view.resource_type_one(resourceTypeID, bus.uow)
         if result is not None:
             return result
-        api_ims_inventory_v1.abort(
-            404, "Resource type {} doesn't exist".format(resourceTypeID))
+        ProblemDetails(
+            api_ims_inventory_v1,
+            404, "Resource type {} doesn't exist".format(
+                resourceTypeID)).abort()
 
 
 # ----------  ResourcePools ---------- #
@@ -253,8 +257,10 @@ class ResourcePoolGetRouter(Resource):
         result = ocloud_view.resource_pool_one(resourcePoolID, bus.uow)
         if result is not None:
             return result
-        api_ims_inventory_v1.abort(
-            404, "Resource pool {} doesn't exist".format(resourcePoolID))
+        ProblemDetails(
+            api_ims_inventory_v1,
+            404, "Resource pool {} doesn't exist".format(
+                resourcePoolID)).abort()
 
 
 # ----------  Resources ---------- #
@@ -352,8 +358,10 @@ class ResourceGetRouter(Resource):
         result = ocloud_view.resource_one(resourceID, bus.uow)
         if result is not None:
             return result
-        api_ims_inventory_v1.abort(
-            404, "Resource {} doesn't exist".format(resourceID))
+        ProblemDetails(
+            api_ims_inventory_v1,
+            404, "Resource {} doesn't exist".format(
+                resourceID)).abort()
 
 
 # ----------  DeploymentManagers ---------- #
@@ -448,9 +456,11 @@ class DeploymentManagerGetRouter(Resource):
             deploymentManagerID, bus.uow, profile)
         if result is not None:
             return result
-        api_ims_inventory_v1.abort(
-            404,
-            "Deployment manager {} doesn't exist".format(deploymentManagerID))
+
+        ProblemDetails(
+            api_ims_inventory_v1,
+            404, "Deployment manager {} doesn't exist".format(
+                deploymentManagerID)).abort()
 
 
 # ----------  Subscriptions ---------- #
@@ -549,8 +559,10 @@ class SubscriptionGetDelRouter(Resource):
             subscriptionID, bus.uow)
         if result is not None:
             return result
-        api_ims_inventory_v1.abort(404, "Subscription {} doesn't exist".format(
-            subscriptionID))
+        ProblemDetails(
+            api_ims_inventory_v1,
+            404, "Subscription {} doesn't exist".format(
+                subscriptionID)).abort()
 
     @api_ims_inventory_v1.doc('Delete subscription by ID')
     @api_ims_inventory_v1.response(204, 'Subscription deleted')