diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 42944556..355007c5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,30 @@ Changelog 4.0.0 (unreleased) ****************** +Features: + +* *Backwards-incompatible*: Custom error handlers receive the + `marshmallow.Schema` instance as the third argument. Update any + functions decorated with `Parser.error_handler` to take a ``schema`` + argument, like so: + +.. code-block:: python + + # 3.x + @parser.error_handler + def handle_error(error, req): + raise CustomError(error.messages) + + + # 4.x + @parser.error_handler + def handle_error(error, req, schema): + raise CustomError(error.messages) + + +See `marshmallow-code/marshmallow#840 (comment) `_ +for more information about this change. + Bug fixes: * *Backwards-incompatible*: Rename ``webargs.async`` to diff --git a/docs/framework_support.rst b/docs/framework_support.rst index a81754dc..a81cd578 100644 --- a/docs/framework_support.rst +++ b/docs/framework_support.rst @@ -31,7 +31,8 @@ When using the :meth:`use_args ` decor Error Handling ++++++++++++++ -Webargs uses Flask's ``abort`` function to raise an ``HTTPException`` when a validation error occurs. If you use the ``Flask.errorhandler`` method to handle errors, you can access validation messages from the ``data`` attribute of an error. +Webargs uses Flask's ``abort`` function to raise an ``HTTPException`` when a validation error occurs. +If you use the ``Flask.errorhandler`` method to handle errors, you can access validation messages from the ``data`` attribute of an error. Here is an example error handler that returns validation messages to the client as JSON. diff --git a/docs/quickstart.rst b/docs/quickstart.rst index bf7cda98..aeb5b330 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -185,14 +185,14 @@ Error Handling -------------- Each parser has a default error handling method. To override the error handling callback, write a function that -receives an error and the request and handles the error. +receives an error, the request, and the `marshmallow.Schema` instance. Then decorate that function with :func:`Parser.error_handler `. .. code-block:: python - from webargs import core + from webargs import flaskparser - parser = core.Parser() + parser = flaskparser.FlaskParser() class CustomError(Exception): @@ -200,7 +200,7 @@ Then decorate that function with :func:`Parser.error_handler