Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
doc: Fixed small error in documentation for register_error_handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Seluj78 committed Sep 23, 2024
1 parent 6798ea8 commit d0a9653
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 6 additions & 4 deletions flask_utils/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,23 @@ def _register_error_handlers(application: Flask) -> None:
.. versionchanged:: 0.5.0
Made the function private. If you want to register the custom error handlers, you need to
pass ``register_error_handlers=True`` to the :class:`~flask_utils.extension.FlaskUtils` class
or to :meth:`~flask_utils.extension.FlaskUtils.init_app`
pass ``register_error_handlers=True`` to the :class:`~flask_utils.extension.FlaskUtils` class
or to :meth:`~flask_utils.extension.FlaskUtils.init_app`
register_error_handlers is ``True`` by default.
.. code-block:: python
from flask import Flask
from flask_utils import FlaskUtils
app = Flask(__name__)
utils = FlaskUtils(app)
utils = FlaskUtils(app, register_error_handlers=True)
# OR
utils = FlaskUtils()
utils.init_app(app)
utils.init_app(app, register_error_handlers=True)
.. versionadded:: 0.1.0
"""
Expand Down
14 changes: 7 additions & 7 deletions flask_utils/errors/_error_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ def _generate_error_dict(error: _BaseFlaskException) -> Dict[str, Any]:
:type error: _BaseFlaskException
:return: Returns a dict containing a json representation of the error
:rtype: dict
:rtype: Dict[str, Any]
:Example:
.. code-block:: python
from flask_utils import ConflictError # or any other error
from flask_utils.errors._error_template import _generate_error_json
from flask_utils.errors._error_template import _generate_error_dict
json = _generate_error_json(error)
json = _generate_error_dict(error)
# Sample output:
# {
# "success": False,
Expand Down Expand Up @@ -67,7 +67,7 @@ def _generate_error_response(error: _BaseFlaskException) -> Response:
.. code-block:: python
from flask_utils.errors import _BaseFlaskException
from flask_utils.errors._error_template import _generate_error_json
from flask_utils.errors._error_template import _generate_error_response
class MyError(_BaseFlaskException):
self.name = "MyError"
Expand All @@ -77,12 +77,12 @@ class MyError(_BaseFlaskException):
error = MyError("This is an error", "This is the solution")
json = _generate_error_json(error, 666)
response = _generate_error_response(error, 666)
.. versionchanged:: 0.8.0
This function was renamed from ``generate_error_json`` to ``_generate_error_response``.
This function was renamed from ``_generate_error_json`` to ``_generate_error_response``.
It now returns a ``flask.Response`` object, calling
:func:`~flask_utils.errors._error_template._generate_error_json` to generate the json.
:func:`~flask_utils.errors._error_template._generate_error_dict` to generate the dict that will be returned.
.. versionadded:: 0.1.0
"""
Expand Down

0 comments on commit d0a9653

Please sign in to comment.