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.6KB

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