diff --git a/InvenTree/InvenTree/api.py b/InvenTree/InvenTree/api.py index c204c0befb..fa8a6739b7 100644 --- a/InvenTree/InvenTree/api.py +++ b/InvenTree/InvenTree/api.py @@ -48,6 +48,22 @@ class InfoView(AjaxView): return JsonResponse(data) +class NotFoundView(AjaxView): + """ + Simple JSON view when accessing an invalid API view. + """ + + permission_classes = [permissions.AllowAny] + + def get(self, request, *args, **kwargs): + + data = { + 'details': _('API endpoint not found') + } + + return JsonResponse(data, status=404) + + class AttachmentMixin: """ Mixin for creating attachment objects, diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index c5b439c0be..a9f53a7014 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -43,7 +43,7 @@ from .views import DynamicJsView from common.views import SettingEdit -from .api import InfoView +from .api import InfoView, NotFoundView from .api import ActionPluginView from users.urls import user_urls @@ -70,6 +70,9 @@ apipatterns = [ # InvenTree information endpoint url(r'^$', InfoView.as_view(), name='api-inventree-info'), + + # Unknown endpoint + url(r'^.*$', NotFoundView.as_view(), name='api-404'), ] settings_urls = [