No Description
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.7KB

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