exception_handle.py 928 B

12345678910111213141516171819202122232425262728293031323334
  1. # -*- coding: utf-8 -*-
  2. # @Time : 2023/7/21 8:43
  3. # @Author : XuJiakai
  4. # @File : exception_handle
  5. # @Software: PyCharm
  6. from data_clean.exception.fetch_exception import FetchException
  7. from data_clean.exception.ruler_validation_exception import RulerValidationException
  8. from data_clean.utils.str_utils import pascal_case_to_snake_case
  9. from data_clean.utils import get_log
  10. log = get_log("exception_handler")
  11. def exception_handle(func):
  12. async def wrapper(self, *args, **kwargs):
  13. tn = pascal_case_to_snake_case(self.__class__.__name__)
  14. result = None
  15. try:
  16. result = await func(self, *args, **kwargs)
  17. except (FetchException, RulerValidationException) as ex:
  18. log.warn("%s", ex)
  19. pass
  20. except Exception as ex:
  21. log.error("出现未知异常:%s", ex)
  22. return result
  23. pass
  24. return wrapper
  25. if __name__ == '__main__':
  26. pass