暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

exceptions.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from lodel import logger
  2. from lodel.plugin.hooks import LodelHook
  3. ##@brief Handles common errors with a Client
  4. class ClientError(Exception):
  5. ##@brief The logger function to use to log the error message
  6. _loglvl = 'warning'
  7. ##@brief Error str
  8. _err_str = "Error"
  9. ##@brief the hook name to trigger with error
  10. _action = 'lodel2_ui_error'
  11. ##@brief the hook payload
  12. _payload = None
  13. ##@brief Constructor
  14. #
  15. #Log message are build using the following format :
  16. #"<client infos> : <_err_str>[ : <msg>]"
  17. def __init__(self, client, msg = ""):
  18. msg = self.build_message(client, msg)
  19. if self._loglvl is not None:
  20. logfun = getattr(logger, self._loglvl)
  21. logfun(msg)
  22. super().__init__(msg)
  23. if self._action is not None:
  24. LodelHook.call_hook(self._action, self, self._payload)
  25. ##@brief build error message
  26. def build_message(self, client, msg):
  27. res = "%s : %s" % (client, self._err_str)
  28. if len(msg) > 0:
  29. res += " : %s" % msg
  30. return res
  31. ##@brief Handles authentication failure errors
  32. class ClientAuthenticationFailure(ClientError):
  33. _loglvl = 'security'
  34. _err_str = 'Authentication failure'
  35. _action = 'lodel2_ui_authentication_failure'
  36. ##@brief Handles permission denied errors
  37. class ClientPermissionDenied(ClientError):
  38. _loglvl = 'security'
  39. _err_str = 'Permission denied'
  40. _action = 'lodel2_ui_permission_denied'
  41. ##@brief Handles common errors on authentication
  42. class ClientAuthenticationError(ClientError):
  43. _loglvl = 'error'
  44. _err_str = 'Authentication error'
  45. _action = 'lodel2_ui_error'