flip_api.utils.api_response
Attributes
Functions
|
Construct a successful API response with default CORS headers. |
|
Construct an error response with logging and error message. |
|
Construct an unhandled error response with logging and generic error message. |
|
Construct a generic API response with default CORS headers. |
Module Contents
- flip_api.utils.api_response.HEADERS
- flip_api.utils.api_response.success(status_code: int = status.HTTP_200_OK, data: dict | None = None) dict
Construct a successful API response with default CORS headers.
- Parameters:
status_code (int) – HTTP status code for the response. Defaults to 200 OK.
data (dict | None) – Response body payload. Defaults to an empty dict when None.
- Returns:
Response envelope with
statusCode,headers, and JSON-encodedbody.- Return type:
dict
- flip_api.utils.api_response.error(status_code: int, error: Exception | Any) dict
Construct an error response with logging and error message.
- Parameters:
status_code (int) – HTTP status code for the response.
error (Exception | Any) – The error to log. If it has a
messageattribute, that is returned to the client; otherwise a generic message is used.
- Returns:
Response envelope with
statusCode,headers, and JSON-encodedbodycontaining the error message.- Return type:
dict
- flip_api.utils.api_response.unhandled_error(status_code: int, error: Exception | Any) dict
Construct an unhandled error response with logging and generic error message.
- Parameters:
status_code (int) – HTTP status code for the response.
error (Exception | Any) – The error to log. Logged at error level when it exposes a
messageattribute.
- Returns:
Response envelope with
statusCode,headers, and JSON-encodedbodycontaining a generic error message.- Return type:
dict
- flip_api.utils.api_response.api_response(status_code: int, body: dict | None = None) dict
Construct a generic API response with default CORS headers.
- Parameters:
status_code (int) – HTTP status code for the response.
body (dict | None) – Response body payload. Defaults to an empty dict when None.
- Returns:
Response envelope with
statusCode,headers, and JSON-encodedbody.- Return type:
dict