Skip to content

Commit 3affd0b

Browse files
committed
handle exception
1 parent e2f8732 commit 3affd0b

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

watcher/cadf_strategy.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,25 +153,30 @@ def determine_cadf_action(self, req, target_type_uri=None):
153153
"""
154154
cadf_action = taxonomy.UNKNOWN
155155

156-
# is this an ../action request with a json body, then check the json body for the openstack action
157-
if common.is_action_request(req):
158-
cadf_action = self._cadf_action_from_body(req.json)
156+
try:
157+
# is this an ../action request with a json body, then check the json body for the openstack action
158+
if common.is_action_request(req):
159+
cadf_action = self._cadf_action_from_body(req.json)
160+
161+
# get target type URI from request path if still unknown
162+
if common.is_none_or_unknown(target_type_uri):
163+
target_type_uri = self.determine_target_type_uri(req)
159164

160-
# get target type URI from request path if still unknown
161-
if common.is_none_or_unknown(target_type_uri):
162-
target_type_uri = self.determine_target_type_uri(req)
165+
# lookup action in custom mapping if one exists
166+
if self.custom_action_config:
167+
custom_cadf_action = self._cadf_action_from_custom_action_config(target_type_uri, req.method, cadf_action)
168+
if not common.is_none_or_unknown(custom_cadf_action):
169+
cadf_action = custom_cadf_action
163170

164-
# lookup action in custom mapping if one exists
165-
if self.custom_action_config:
166-
custom_cadf_action = self._cadf_action_from_custom_action_config(target_type_uri, req.method, cadf_action)
167-
if not common.is_none_or_unknown(custom_cadf_action):
168-
cadf_action = custom_cadf_action
171+
# if nothing was found, return cadf action based on request method and path
172+
if common.is_none_or_unknown(cadf_action):
173+
cadf_action = self._cadf_action_from_method_and_target_type_uri(req.method, target_type_uri)
169174

170-
# if nothing was found, return cadf action based on request method and path
171-
if common.is_none_or_unknown(cadf_action):
172-
cadf_action = self._cadf_action_from_method_and_target_type_uri(req.method, target_type_uri)
175+
except Exception as e:
176+
self.logger.debug("error while determining cadf action: {0}".format(str(e)))
173177

174-
return cadf_action
178+
finally:
179+
return cadf_action
175180

176181
def _cadf_action_from_method_and_target_type_uri(self, method, path):
177182
"""
@@ -235,7 +240,7 @@ def _cadf_action_from_body(self, json_body):
235240
if os_action and len(os_action) > 2:
236241
# add prefix to os_action
237242
cadf_action = self.cadf_os_action_prefix + str(os_action)
238-
return
243+
239244
except Exception as e:
240245
self.logger.debug("error while determining action from json body: {0}".format(str(e)))
241246

0 commit comments

Comments
 (0)