Exceptions
The library provides a hierarchy of exceptions for handling API errors gracefully.
Exception Hierarchy
BetterStackError (base)
├── APIError
│ ├── AuthenticationError (401)
│ ├── ForbiddenError (403)
│ ├── NotFoundError (404)
│ ├── RateLimitError (429)
│ └── ServerError (5xx)
├── ValidationError
└── ConfigurationError
Usage Example
from betterstack.uptime import UptimeAPI
from betterstack.uptime.objects import Monitor
from betterstack.uptime.exceptions import (
AuthenticationError,
NotFoundError,
RateLimitError,
APIError,
)
api = UptimeAPI("your-token")
try:
monitor = Monitor.get_all_instances(api)
except AuthenticationError:
print("Invalid API token")
except NotFoundError:
print("Resource not found")
except RateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after} seconds")
except APIError as e:
print(f"API error {e.status_code}: {e.message}")
Exception Reference
BetterStackError
APIError
- class betterstack.uptime.exceptions.APIError(message: str, status_code: int, response_body: dict | None = None)[source]
Bases:
BetterStackErrorError returned from the BetterStack API.
AuthenticationError
ForbiddenError
NotFoundError
RateLimitError
ServerError
ValidationError
- class betterstack.uptime.exceptions.ValidationError[source]
Bases:
BetterStackErrorLocal validation error (e.g., invalid parameters).
ConfigurationError
- class betterstack.uptime.exceptions.ConfigurationError[source]
Bases:
BetterStackErrorConfiguration error (e.g., missing required settings).