aboutsummaryrefslogtreecommitdiffstats
path: root/src/nvd/exceptions.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvd/exceptions.py')
-rw-r--r--src/nvd/exceptions.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/nvd/exceptions.py b/src/nvd/exceptions.py
new file mode 100644
index 0000000..a4c774b
--- /dev/null
+++ b/src/nvd/exceptions.py
@@ -0,0 +1,61 @@
+"""Custom exceptions for the NVD API client."""
+
+from typing import Any, Optional
+
+
+class NVDError(Exception):
+ """Base exception for all NVD API errors."""
+
+ def __init__(self, message: str, response: Optional[Any] = None) -> None:
+ super().__init__(message)
+ self.message = message
+ self.response = response
+
+
+class RateLimitError(NVDError):
+ """Raised when rate limit is exceeded."""
+
+ def __init__(
+ self,
+ message: str = "Rate limit exceeded",
+ retry_after: Optional[int] = None,
+ response: Optional[Any] = None,
+ ) -> None:
+ super().__init__(message, response)
+ self.retry_after = retry_after
+
+
+class AuthenticationError(NVDError):
+ """Raised when authentication fails (invalid API key)."""
+
+ pass
+
+
+class ValidationError(NVDError):
+ """Raised when request parameters are invalid."""
+
+ pass
+
+
+class NotFoundError(NVDError):
+ """Raised when a resource is not found (404)."""
+
+ pass
+
+
+class ServerError(NVDError):
+ """Raised when the NVD API returns a server error (5xx)."""
+
+ pass
+
+
+class NetworkError(NVDError):
+ """Raised when a network error occurs."""
+
+ pass
+
+
+class ResponseError(NVDError):
+ """Raised when response parsing fails."""
+
+ pass