-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
70 lines (38 loc) · 1.58 KB
/
exceptions.py
File metadata and controls
70 lines (38 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""Custom exceptions for the Notion SDK."""
class NotionError(Exception):
"""Base exception for all Notion SDK errors."""
pass
class NotionAPIError(NotionError):
"""Raised when a Notion API request fails."""
def __init__(self, message: str, status_code: int | None = None, error_code: str | None = None):
super().__init__(message)
self.status_code = status_code
self.error_code = error_code
def __str__(self) -> str:
return f"NotionAPIError: {self.args[0]} (Status: {self.status_code}, Code: {self.error_code})"
class NotionRateLimitError(NotionAPIError):
"""Raised when the Notion API rate limit is exceeded."""
def __init__(self, message: str = "Rate limit exceeded", retry_after: int | None = None):
super().__init__(message, status_code=429, error_code="rate_limited")
self.retry_after = retry_after
class NotionBadRequestError(NotionAPIError):
"""Raised for 400 Bad Request errors."""
pass
class NotionAuthenticationError(NotionAPIError):
"""Raised for 401 Unauthorized errors."""
pass
class NotionPermissionError(NotionAPIError):
"""Raised for 403 Forbidden errors."""
pass
class NotionNotFoundError(NotionAPIError):
"""Raised for 404 Not Found errors."""
pass
class NotionConflictError(NotionAPIError):
"""Raised for 409 Conflict errors."""
pass
class NotionInternalServerError(NotionAPIError):
"""Raised for 5xx server errors."""
pass
class NotionServiceUnavailableError(NotionAPIError):
"""Raised for 503 Service Unavailable errors."""
pass