statuspro_public_api_client.utils¶
statuspro_public_api_client.utils
¶
Utility functions for working with StatusPro API responses.
Helpers for unwrapping generated responses, extracting data, and raising typed errors on API failures.
Classes¶
APIError(message, status_code, error_response=None)
¶
AuthenticationError(message, status_code, error_response=None)
¶
Bases: APIError
Raised when authentication fails (401).
Source code in statuspro_public_api_client/utils.py
RateLimitError(message, status_code, error_response=None)
¶
Bases: APIError
Raised when rate limit is exceeded (429).
Source code in statuspro_public_api_client/utils.py
ServerError(message, status_code, error_response=None)
¶
Bases: APIError
Raised when a server error occurs (5xx).
Source code in statuspro_public_api_client/utils.py
ValidationError(message, status_code, error_response=None)
¶
Bases: APIError
Raised when request validation fails (422).
The validation_errors attribute is a dict[str, list[str]] mapping
field name to the list of human-readable error messages that StatusPro
returned for that field.
Source code in statuspro_public_api_client/utils.py
Functions¶
get_error_message(response)
¶
Extract message from an error response, if present.
Source code in statuspro_public_api_client/utils.py
handle_response(response, *, on_success=None, on_error=None, raise_on_error=False)
¶
Call on_success with parsed data for 2xx, on_error with an APIError otherwise.
Source code in statuspro_public_api_client/utils.py
is_error(response)
¶
is_success(response)
¶
unwrap(response, *, raise_on_error=True)
¶
Unwrap a Response and return parsed data, raising typed errors on failure.
Parameters:
-
response(Response[T]) –Response object from a generated API call.
-
raise_on_error(bool, default:True) –If True (default), raise an APIError subclass for non-2xx responses; if False, return None.
Returns:
-
T | None–The parsed response body.
Raises:
-
AuthenticationError–401
-
ValidationError–422
-
RateLimitError–429
-
ServerError–5xx
-
APIError–other non-2xx statuses
Source code in statuspro_public_api_client/utils.py
unwrap_as(response, expected_type, *, raise_on_error=True)
¶
Unwrap and assert the parsed body is of the expected type.
Source code in statuspro_public_api_client/utils.py
unwrap_data(response, *, raise_on_error=True, default=None)
¶
Unwrap a list response and extract the data array.
For StatusPro's wrapped list endpoints like GET /orders which return
{"data": [...], "meta": {...}}. For raw-array endpoints like
GET /statuses, use unwrap() directly — the parsed response is the
list itself.