X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=a1%2Fcontroller.py;fp=a1%2Fcontroller.py;h=289cf9a221d3bda3c982118a2fd8cecce0b5eaa1;hb=6803b12d1c2af87c57d7dccaced70b49bcb44815;hp=23ef804cb7a75bac264806fa939789752f3bbbe5;hpb=20d87ede528b9c509fe1b0c51c6383b8d307c2c8;p=ric-plt%2Fa1.git diff --git a/a1/controller.py b/a1/controller.py index 23ef804..289cf9a 100644 --- a/a1/controller.py +++ b/a1/controller.py @@ -28,20 +28,25 @@ from a1 import a1rmr, exceptions, data mdc_logger = Logger(name=__name__) +def _log_build_http_resp(exception, http_resp_code): + """ + helper method that logs the exception and returns a tuple of (str, int) as a http response + """ + msg = repr(exception) + mdc_logger.warning("Request failed, returning {0}: {1}".format(http_resp_code, msg)) + return msg, http_resp_code + + def _try_func_return(func): """ helper method that runs the function and returns a detailed http response if an exception is raised. """ try: return func() - except (ValidationError, exceptions.PolicyTypeAlreadyExists, exceptions.CantDeleteNonEmptyType) as exc: - msg = repr(exc) - mdc_logger.warning("Request failed, returning 400: {0}".format(msg)) - return msg, 400 + except (ValidationError, exceptions.PolicyTypeAlreadyExists, exceptions.PolicyTypeIdMismatch, exceptions.CantDeleteNonEmptyType) as exc: + return _log_build_http_resp(exc, 400) except (exceptions.PolicyTypeNotFound, exceptions.PolicyInstanceNotFound) as exc: - msg = repr(exc) - mdc_logger.warning("Request failed, returning 404: {0}".format(msg)) - return msg, 404 + return _log_build_http_resp(exc, 404) except (RejectedByBackend, NotConnected, BackendError) as exc: """ These are SDL errors. At the time of development here, we do not have a good understanding @@ -52,10 +57,7 @@ def _try_func_return(func): For now, we log, and 503, and investigate the logs later to improve the handling/reporting. """ # mdc_logger.exception(exc) # waiting for https://jira.o-ran-sc.org/browse/RIC-39 - msg = repr(exc) - mdc_logger.warning("Request failed, returning 503: {0}".format(msg)) - return msg, 503 - + return _log_build_http_resp(exc, 503) # let other types of unexpected exceptions blow up and log