diff options
| author | Louis Burda <dev@sinitax.com> | 2026-01-30 03:04:01 +0100 |
|---|---|---|
| committer | Louis Burda <dev@sinitax.com> | 2026-01-30 03:04:01 +0100 |
| commit | f6487c615cff023db1574e2c23db78bf02a43709 (patch) | |
| tree | 8a0e793a8ea28b2a5eef5dcd509b6c6a2466ee1c /src/nvd/exceptions.py | |
| download | nvdb-py-main.tar.gz nvdb-py-main.zip | |
Diffstat (limited to 'src/nvd/exceptions.py')
| -rw-r--r-- | src/nvd/exceptions.py | 61 |
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 |
