Skip to content

Commit 6095023

Browse files
feat(platform): add custom exception hierarchy (GAP-7)
Add PlatformError base class and 5 specific subclasses: - NotFoundError (404) - resource not found - DuplicateError (409) - resource already exists - AuthenticationError (401) - invalid credentials - AuthorizationError (403) - insufficient permissions - ValidationError (422) - invalid input data Each exception includes default message and accepts custom messages. Importable from praisonai_platform.exceptions. Co-authored-by: MervinPraison <MervinPraison@users.noreply.github.com>
1 parent d76b56e commit 6095023

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Custom exception hierarchy for the platform package."""
2+
3+
4+
class PlatformError(Exception):
5+
"""Base exception for all platform errors."""
6+
7+
def __init__(self, message: str = "A platform error occurred"):
8+
self.message = message
9+
super().__init__(message)
10+
11+
12+
class NotFoundError(PlatformError):
13+
"""Raised when a requested resource is not found (maps to HTTP 404)."""
14+
15+
def __init__(self, message: str = "Resource not found"):
16+
super().__init__(message)
17+
18+
19+
class DuplicateError(PlatformError):
20+
"""Raised when a resource already exists (maps to HTTP 409)."""
21+
22+
def __init__(self, message: str = "Resource already exists"):
23+
super().__init__(message)
24+
25+
26+
class AuthenticationError(PlatformError):
27+
"""Raised when authentication credentials are invalid (maps to HTTP 401)."""
28+
29+
def __init__(self, message: str = "Authentication failed"):
30+
super().__init__(message)
31+
32+
33+
class AuthorizationError(PlatformError):
34+
"""Raised when user lacks sufficient permissions (maps to HTTP 403)."""
35+
36+
def __init__(self, message: str = "Insufficient permissions"):
37+
super().__init__(message)
38+
39+
40+
class ValidationError(PlatformError):
41+
"""Raised when input data is invalid (maps to HTTP 422)."""
42+
43+
def __init__(self, message: str = "Invalid input data"):
44+
super().__init__(message)

0 commit comments

Comments
 (0)