Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

exceptions.py 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # @package lodel.auth.exceptions
  2. # @brief Defines the specific exceptions used in the authentication process
  3. from lodel.context import LodelContext
  4. LodelContext.expose_modules(globals(), {
  5. 'lodel.logger': 'logger',
  6. 'lodel.plugin.hooks': ['LodelHook']})
  7. ## @brief Handles common errors with a Client
  8. class ClientError(Exception):
  9. ## @brief The logger function to use to log the error message
  10. _loglvl = 'warning'
  11. ## @brief Error string
  12. _err_str = "Error"
  13. ## @brief the hook name to trigger with error
  14. _action = 'lodel2_ui_error'
  15. ## @brief the hook payload
  16. _payload = None
  17. ## @brief Constructor
  18. #
  19. # Log messages are built using the following format :
  20. # "<client infos> : <_err_str>[ : <msg>]"
  21. # @param client Client : object containing the client's data
  22. # @param msg str : message string to use
  23. def __init__(self, client, msg = ""):
  24. msg = self.build_message(client, msg)
  25. if self._loglvl is not None:
  26. logfun = getattr(logger, self._loglvl)
  27. logfun(msg)
  28. super().__init__(msg)
  29. if self._action is not None:
  30. LodelHook.call_hook(self._action, self, self._payload)
  31. ## @brief Builds an error message
  32. # @param client Client
  33. # @param msg str
  34. def build_message(self, client, msg):
  35. res = "%s : %s" % (client, self._err_str)
  36. if len(msg) > 0:
  37. res += " : %s" % msg
  38. return res
  39. ## @brief Handles authentication failure errors
  40. class ClientAuthenticationFailure(ClientError):
  41. ## @brief Log Level
  42. _loglvl = 'security'
  43. ## @brief Error string
  44. _err_str = 'Authentication failure'
  45. ## @brief Hook to trigger
  46. _action = 'lodel2_ui_authentication_failure'
  47. ##@brief Handles permission denied errors
  48. class ClientPermissionDenied(ClientError):
  49. ## @brief Log level
  50. _loglvl = 'security'
  51. ## @brief Error string
  52. _err_str = 'Permission denied'
  53. ## @brief Hook to trigger
  54. _action = 'lodel2_ui_permission_denied'
  55. ##@brief Handles common errors on authentication
  56. class ClientAuthenticationError(ClientError):
  57. ## @brief Log level
  58. _loglvl = 'error'
  59. ## @brief Error string
  60. _err_str = 'Authentication error'
  61. ## @brief Hook to trigger
  62. _action = 'lodel2_ui_error'