Skip to content

flask-buzz Reference

flask_buzz

FlaskBuzz

Bases: Buzz

build_error_handler classmethod
build_error_handler(
    *tasks: FlaskBuzzTask,
) -> tuple[type[Self], FlaskBuzzHandler]

Provides a generic error function that packages a flask_buzz exception so that it can be handled nicely by the flask error handler:

app.register_error_handler(FlaskBuzz, FlaskBuzz.build_error_handler())

Additionally, extra tasks may be applied to the error prior to packaging:

app.register_error_handler(FlaskBuzz, build_error_handler(print, lambda e: jawa(e)))

This latter example will print the error to stdout and also call the jawa() function with the error prior to packaging it for flask's handler

jsonify
jsonify(
    status_code: int | None = None,
    message: str | None = None,
    headers: HeadersValue | None = None,
    **kwargs: Any,
)

Returns a representation of the error in a jsonic form that is compatible with flask's error handling.

Keyword arguments allow custom error handlers to override parts of the exception when it is jsonified.

If debug is set, the stringified exception will be included in the response payload. For apps running in production or publicly should not run in debug mode as this could expose internal information to clients.

Args:

status_code: The status code to include in the response. If not supplied, use instance status_code.
message:     The message to include in the response. If not supplied, use instance message. If debug
             is set and the base_message is not None, use the base_message instead. This is important,
             because if the exception was raised by `handle_errors`, the full message will return
             details of the handled exception as well as the base message. This information should
             probably not be returned to the client.
headers:     The headers to attach to the response. If not supplied, use instance headers. If the
             instance has no headers, don't include headers.
kwargs:      Additional fields that should be set in the response body. These must be JSON
             serializable.