Skip to content

add prefix to config setting #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion flask_restx/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import re
import six
import sys
import warnings

from collections import OrderedDict
from functools import wraps, partial
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down