Skip to content

Commit 6b6baf7

Browse files
committed
feat: no key provided class
1 parent b3d64fd commit 6b6baf7

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/fr24sdk/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
TransportError,
1414
ApiError,
1515
AuthenticationError,
16+
NoApiKeyError,
1617
RateLimitError,
1718
PaymentRequiredError,
1819
BadRequestError,
@@ -26,6 +27,7 @@
2627
"TransportError",
2728
"ApiError",
2829
"AuthenticationError",
30+
"NoApiKeyError",
2931
"RateLimitError",
3032
"PaymentRequiredError",
3133
"BadRequestError",

src/fr24sdk/exceptions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ class AuthenticationError(ApiError):
6666
pass
6767

6868

69+
class NoApiKeyError(Fr24SdkError):
70+
"""Indicates that no API key was provided for authentication.
71+
72+
This is a specific type of authentication error that occurs when the SDK
73+
is used without providing an API token, either through the constructor
74+
or the FR24_API_TOKEN environment variable.
75+
76+
Unlike other ApiError subclasses, this error is raised before any HTTP
77+
request is made, so it doesn't include request/response context.
78+
"""
79+
80+
def __init__(self, message: str):
81+
super().__init__(message)
82+
83+
6984
class RateLimitError(ApiError):
7085
"""Indicates that the API rate limit has been exceeded (402 Payment Required or 429 Too Many Requests)."""
7186

src/fr24sdk/transport.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .exceptions import (
1313
ApiError,
1414
AuthenticationError,
15+
NoApiKeyError,
1516
RateLimitError,
1617
TransportError,
1718
PaymentRequiredError,
@@ -73,6 +74,14 @@ def request(
7374
) -> httpx.Response:
7475
"""Makes an HTTP request to the API."""
7576

77+
# Check if API token is available before making the request
78+
if not self.api_token:
79+
raise NoApiKeyError(
80+
"No API key provided. Please set the FR24_API_TOKEN environment variable "
81+
"or pass an api_token parameter when creating the Client. "
82+
"For more information, see https://fr24api.flightradar24.com/docs"
83+
)
84+
7685
request_headers = self._get_default_headers()
7786
if headers:
7887
request_headers.update(headers)

0 commit comments

Comments
 (0)