flask_buzz package¶
-
exception
flask_buzz.
FlaskBuzz
(message, *format_args, **format_kwds)¶ Bases:
buzz.Buzz
-
static
build_error_handler
(*tasks)¶ 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: foo(e)), )
This latter example will print the error to stdout and also call the foo() function with the error prior to packaing it for flask’s handler
-
static
build_error_handler_for_flask_restplus
(*tasks)¶ Provides a generic error function that packages a flask_buzz exception so that it can be handled by the flask-restplus error handler:
@api.errorhandler(SFBDError) def do_it(error): return SFBDError.build_error_handler_for_flask_restplus()()
or:
api.errorhandler(SFBDError)( SFBDError.build_error_handler_for_flask_restplus() )
Flask-restplus handles exceptions differently than Flask, and it is awkward. For further reading on why special functionality is needed for flask-restplus, observe and compare:
Additionally, extra tasks may be applied to the error prior to packaging as in
build_error_handler
-
headers
= None¶
-
jsonify
(status_code=None, message=None, headers=None)¶ 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
-
classmethod
register_error_handler_with_flask_restplus
(api, *tasks)¶ Registers an error handler for FlaskBuzz derived errors that are currently imported. This is useful since flask-restplus (prior to 0.11.0) does not handle derived errors. This is probably the easist way to register error handlers for FlaskBuzz errors with flask-restplus:
FlaskBuzz.register_error_handler_with_flask_restplus( api, print, lambda e: foo(e), )
-
status_code
= 400¶
-
static
-
flask_buzz.
error_handler
(error)¶ Deprecated: Use build_error_handler