errors.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. """
  2. -----------------------------------------------------------------------------------------
  3. INTERSEL - 4 cité d'Hauteville - 75010 PARIS
  4. RCS PARIS 488 379 660 - NAF 721Z
  5. File : core/errors.py
  6. Object : Error classes definitions for the MCP server
  7. -----------------------------------------------------------------------------------------
  8. Modifications :
  9. - 2026/01/27 - Damien Lugagne-Delpon - V1.0.0 - Creation
  10. -----------------------------------------------------------------------------------------
  11. @copyright : Intersel 2026
  12. @author : Damien Lugagne-Delpon - damien.lugagne-delpon@livinweb.fr
  13. @version : 1.0.0 (to be updated to the current_version of the developed software if file is touched)
  14. -----------------------------------------------------------------------------------------
  15. """
  16. class LWCopilotError(Exception):
  17. """Exception de base pour LW-Copilot."""
  18. def __init__(self, message: str, code: int = 500, details: dict = None):
  19. super().__init__(message)
  20. self.message = message
  21. self.code = code
  22. self.details = details or {}
  23. class AuthenticationError(LWCopilotError):
  24. """Erreur d'authentification avec l'API MODX."""
  25. def __init__(self, message: str = "Authentication failed", details: dict = None):
  26. super().__init__(message, code=401, details=details)
  27. class PermissionError(LWCopilotError):
  28. """Droits insuffisants pour accéder à une ressource."""
  29. def __init__(self, message: str = "Permission denied", details: dict = None):
  30. super().__init__(message, code=403, details=details)
  31. class ResourceNotFoundError(LWCopilotError):
  32. """Ressource non trouvée."""
  33. def __init__(self, message: str = "Resource not found", details: dict = None):
  34. super().__init__(message, code=404, details=details)
  35. class TemplateNotFoundError(LWCopilotError):
  36. """Template non trouvée."""
  37. def __init__(self, message: str = "Template not found", details: dict = None):
  38. super().__init__(message, code=404, details=details)
  39. class ValidationError(LWCopilotError):
  40. """Erreur de validation des paramètres."""
  41. def __init__(self, message: str = "Validation error", details: dict = None):
  42. super().__init__(message, code=400, details=details)
  43. class InvalidToolCallError(LWCopilotError):
  44. """Schéma d'appel d'outil invalide."""
  45. def __init__(self, message: str = "Invalid tool call", details: dict = None):
  46. super().__init__(message, code=400, details=details)
  47. class ContextError(LWCopilotError):
  48. """Erreur de gestion du contexte."""
  49. def __init__(self, message: str = "Context error", details: dict = None):
  50. super().__init__(message, code=400, details=details)
  51. class MODXAPIError(LWCopilotError):
  52. """Erreur générique de l'API MODX."""
  53. def __init__(self, message: str = "MODX API error", code: int = 500, details: dict = None):
  54. super().__init__(message, code=code, details=details)
  55. class InternalError(LWCopilotError):
  56. """Erreur interne du serveur."""
  57. def __init__(self, message: str = "Internal server error", details: dict = None):
  58. super().__init__(message, code=500, details=details)