Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/fr24sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
TransportError,
ApiError,
AuthenticationError,
NoApiKeyError,
RateLimitError,
PaymentRequiredError,
BadRequestError,
Expand All @@ -26,6 +27,7 @@
"TransportError",
"ApiError",
"AuthenticationError",
"NoApiKeyError",
"RateLimitError",
"PaymentRequiredError",
"BadRequestError",
Expand Down
15 changes: 15 additions & 0 deletions src/fr24sdk/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ class AuthenticationError(ApiError):
pass


class NoApiKeyError(Fr24SdkError):
"""Indicates that no API key was provided for authentication.

This is a specific type of authentication error that occurs when the SDK
is used without providing an API token, either through the constructor
or the FR24_API_TOKEN environment variable.

Unlike other ApiError subclasses, this error is raised before any HTTP
request is made, so it doesn't include request/response context.
"""

def __init__(self, message: str):
super().__init__(message)


class RateLimitError(ApiError):
"""Indicates that the API rate limit has been exceeded (402 Payment Required or 429 Too Many Requests)."""

Expand Down
9 changes: 9 additions & 0 deletions src/fr24sdk/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .exceptions import (
ApiError,
AuthenticationError,
NoApiKeyError,
RateLimitError,
TransportError,
PaymentRequiredError,
Expand Down Expand Up @@ -73,6 +74,14 @@ def request(
) -> httpx.Response:
"""Makes an HTTP request to the API."""

# Check if API token is available before making the request
if not self.api_token:
raise NoApiKeyError(
"No API key provided. Please set the FR24_API_TOKEN environment variable "
"or pass an api_token parameter when creating the Client. "
"For more information, see https://fr24api.flightradar24.com/docs"
)

request_headers = self._get_default_headers()
if headers:
request_headers.update(headers)
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.