-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_exceptions.py
More file actions
86 lines (56 loc) · 1.8 KB
/
Copy path_exceptions.py
File metadata and controls
86 lines (56 loc) · 1.8 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
Stack0 SDK Exceptions
"""
from __future__ import annotations
from typing import Any
class Stack0Error(Exception):
"""Base exception for Stack0 SDK"""
pass
class APIError(Stack0Error):
"""Exception raised when the API returns an error response"""
def __init__(
self,
message: str,
status_code: int,
code: str | None = None,
response: dict[str, Any] | None = None,
) -> None:
super().__init__(message)
self.message = message
self.status_code = status_code
self.code = code
self.response = response
def __str__(self) -> str:
if self.code:
return f"[{self.code}] {self.message} (HTTP {self.status_code})"
return f"{self.message} (HTTP {self.status_code})"
class AuthenticationError(APIError):
"""Exception raised when authentication fails (401)"""
pass
class PermissionError(APIError):
"""Exception raised when permission is denied (403)"""
pass
class NotFoundError(APIError):
"""Exception raised when a resource is not found (404)"""
pass
class RateLimitError(APIError):
"""Exception raised when rate limit is exceeded (429)"""
def __init__(
self,
message: str,
status_code: int = 429,
code: str | None = None,
response: dict[str, Any] | None = None,
retry_after: int | None = None,
) -> None:
super().__init__(message, status_code, code, response)
self.retry_after = retry_after
class ValidationError(APIError):
"""Exception raised when request validation fails (400)"""
pass
class TimeoutError(Stack0Error):
"""Exception raised when an operation times out"""
pass
class NetworkError(Stack0Error):
"""Exception raised when a network error occurs"""
pass