Core¶
Shared infrastructure used by all SDK clients.
core
¶
Core module for the Griddy SDK.
This module provides shared functionality used across all SDK modules:
- Exceptions: Custom exception classes for different error scenarios
- Models: Base Pydantic models for data validation
Example
from griddy.core import GriddyError try: ... data = sdk.some_method() ... except GriddyError as e: ... print(f"Error: {e.message}")
APIError
¶
Bases: GriddyError
Raised when an API request fails.
This exception is raised for general API errors, including server errors (5xx status codes) and client errors that don't fit more specific categories.
Example
try: ... result = nfl.games.get_games(season=2024) ... except APIError as e: ... if e.status_code and e.status_code >= 500: ... print("Server error - retry later") ... else: ... print(f"API error: {e.message}")
Source code in src/griddy/core/exceptions.py
AuthenticationError
¶
Bases: GriddyError
Raised when authentication fails.
This exception is raised when the API returns a 401 status code, indicating the request lacks valid authentication credentials.
Example
try: ... result = nfl.games.get_games(season=2024) ... except AuthenticationError: ... print("Token expired. Please re-authenticate.")
Source code in src/griddy/core/exceptions.py
GriddyError
¶
Bases: Exception
Base exception for all Griddy SDK errors.
All SDK-specific exceptions inherit from this class, allowing you to catch all SDK errors with a single except clause.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
Human-readable error description. |
|
status_code |
HTTP status code from the API response, if applicable. |
|
response_data |
Raw response data from the API, if available. |
Example
try: ... result = nfl.games.get_games(season=2024) ... except GriddyError as e: ... print(f"Error: {e.message}") ... print(f"Status: {e.status_code}") ... print(f"Data: {e.response_data}")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
required |
status_code
|
int | None
|
HTTP status code from the API response. |
None
|
response_data
|
dict[str, Any] | None
|
Raw response data from the API. |
None
|
Source code in src/griddy/core/exceptions.py
NotFoundError
¶
Bases: GriddyError
Raised when a requested resource is not found.
This exception is raised when the API returns a 404 status code, indicating the requested resource does not exist.
Example
try: ... player = nfl.players.get_player(player_id="invalid_id") ... except NotFoundError as e: ... print(f"Player not found: {e.message}") ... player = None
Source code in src/griddy/core/exceptions.py
RateLimitError
¶
Bases: GriddyError
Raised when the API rate limit is exceeded.
This exception is raised when the API returns a 429 status code, indicating too many requests have been made in a given time period.
Attributes:
| Name | Type | Description |
|---|---|---|
retry_after |
Number of seconds to wait before retrying, if provided by the API in the Retry-After header. |
Example
import time try: ... result = nfl.games.get_games(season=2024) ... except RateLimitError as e: ... wait_time = e.retry_after or 60 ... print(f"Rate limited. Waiting {wait_time} seconds...") ... time.sleep(wait_time)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
required |
retry_after
|
int | None
|
Seconds to wait before retrying, from Retry-After header. |
None
|
**kwargs
|
Any
|
Additional arguments passed to GriddyError. |
{}
|
Source code in src/griddy/core/exceptions.py
ValidationError
¶
Bases: GriddyError
Raised when request validation fails.
This exception is raised when the request parameters fail validation, either client-side or when the API returns a 400 status code.
Example
try: ... result = nfl.games.get_games(season="invalid") ... except ValidationError as e: ... print(f"Invalid parameters: {e.message}")