flip_api.utils.api_response

Attributes

HEADERS

Functions

success(→ dict)

Construct a successful API response with default CORS headers.

error(→ dict)

Construct an error response with logging and error message.

unhandled_error(→ dict)

Construct an unhandled error response with logging and generic error message.

api_response(→ dict)

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-encoded body.

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 message attribute, that is returned to the client; otherwise a generic message is used.

Returns:

Response envelope with statusCode, headers, and JSON-encoded body containing 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 message attribute.

Returns:

Response envelope with statusCode, headers, and JSON-encoded body containing 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-encoded body.

Return type:

dict