diff --git a/doc/quickstart.rst b/doc/quickstart.rst index b1696666..d223d56d 100644 --- a/doc/quickstart.rst +++ b/doc/quickstart.rst @@ -225,7 +225,7 @@ You can also match parts of the path as variables to your resource methods. If a request does not match any of your application's endpoints, Flask-RESTX will return a 404 error message with suggestions of other endpoints that closely match the requested endpoint. - This can be disabled by setting ``ERROR_404_HELP`` to ``False`` in your application config. + This can be disabled by setting ``RESTX_ERROR_404_HELP`` to ``False`` in your application config. Argument Parsing diff --git a/flask_restx/api.py b/flask_restx/api.py index 0eefce8d..75ec0954 100644 --- a/flask_restx/api.py +++ b/flask_restx/api.py @@ -9,6 +9,7 @@ import re import six import sys +import warnings from collections import OrderedDict from functools import wraps, partial @@ -219,6 +220,7 @@ def init_app(self, app, **kwargs): else: self.blueprint = app + def _init_app(self, app): """ Perform initialization actions with the given :class:`flask.Flask` object. @@ -250,6 +252,16 @@ def _init_app(self, app): app.config.setdefault("RESTX_MASK_SWAGGER", True) app.config.setdefault("RESTX_INCLUDE_ALL_MODELS", False) + # check for deprecated config variable names + if "ERROR_404_HELP" in app.config: + app.config['RESTX_ERROR_404_HELP'] = app.config['ERROR_404_HELP'] + warnings.warn( + "'ERROR_404_HELP' config setting is deprecated and will be " + "removed in the future. Use 'RESTX_ERROR_404_HELP' instead.", + DeprecationWarning + ) + + def __getattr__(self, name): try: return getattr(self.default_namespace, name) @@ -709,7 +721,7 @@ def handle_error(self, e): elif ( code == HTTPStatus.NOT_FOUND - and current_app.config.get("ERROR_404_HELP", True) + and current_app.config.get("RESTX_ERROR_404_HELP", True) and include_message_in_response ): data["message"] = self._help_on_404(data.get("message", None)) diff --git a/tests/test_errors.py b/tests/test_errors.py index 98e24d15..10fdc2ea 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -480,7 +480,7 @@ def test_handle_smart_errors(self, app): assert response.status_code == 404 assert "did you mean /foo ?" in response.data.decode() - app.config["ERROR_404_HELP"] = False + app.config["RESTX_ERROR_404_HELP"] = False response = api.handle_error(NotFound()) assert response.status_code == 404