Refactor MagnumException to reduce complexity
Reduce cyclomatic complexity of MagnumException to below 10. Remove exception handling and optimise the logging when the kwargs does not match the message. Change-Id: I4fd6ba96be9dff485cdd8bde9750f2d584c1ec63 Closes-Bug: #1501331
This commit is contained in:
parent
82003a56e5
commit
ee52fbbcba
|
@ -193,11 +193,8 @@ class MagnumException(Exception):
|
|||
def __init__(self, message=None, **kwargs):
|
||||
self.kwargs = kwargs
|
||||
|
||||
if 'code' not in self.kwargs:
|
||||
try:
|
||||
self.kwargs['code'] = self.code
|
||||
except AttributeError:
|
||||
pass
|
||||
if 'code' not in self.kwargs and hasattr(self, 'code'):
|
||||
self.kwargs['code'] = self.code
|
||||
|
||||
if message:
|
||||
self.message = message
|
||||
|
@ -207,10 +204,8 @@ class MagnumException(Exception):
|
|||
except Exception as e:
|
||||
# kwargs doesn't match a variable in the message
|
||||
# log the issue and the kwargs
|
||||
LOG.exception(_LE('Exception in string format operation'))
|
||||
for name, value in kwargs.items():
|
||||
LOG.error(_LE("%(name)s: %(value)s") %
|
||||
{'name': name, 'value': value})
|
||||
LOG.exception(_LE('Exception in string format operation, '
|
||||
'kwargs: %s') % kwargs)
|
||||
try:
|
||||
if CONF.fatal_exception_format_errors:
|
||||
raise e
|
||||
|
|
Loading…
Reference in New Issue