mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Merge pull request #1371 from SchrodingersGat/api-404
Adds "404" response when asking for an API endpoint that does not exist
This commit is contained in:
commit
5cdae04c62
@ -48,6 +48,23 @@ class InfoView(AjaxView):
|
|||||||
return JsonResponse(data)
|
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'),
|
||||||
|
'url': request.build_absolute_uri(),
|
||||||
|
}
|
||||||
|
|
||||||
|
return JsonResponse(data, status=404)
|
||||||
|
|
||||||
|
|
||||||
class AttachmentMixin:
|
class AttachmentMixin:
|
||||||
"""
|
"""
|
||||||
Mixin for creating attachment objects,
|
Mixin for creating attachment objects,
|
||||||
|
@ -43,7 +43,7 @@ from .views import DynamicJsView
|
|||||||
|
|
||||||
from common.views import SettingEdit
|
from common.views import SettingEdit
|
||||||
|
|
||||||
from .api import InfoView
|
from .api import InfoView, NotFoundView
|
||||||
from .api import ActionPluginView
|
from .api import ActionPluginView
|
||||||
|
|
||||||
from users.urls import user_urls
|
from users.urls import user_urls
|
||||||
@ -70,6 +70,9 @@ apipatterns = [
|
|||||||
|
|
||||||
# InvenTree information endpoint
|
# InvenTree information endpoint
|
||||||
url(r'^$', InfoView.as_view(), name='api-inventree-info'),
|
url(r'^$', InfoView.as_view(), name='api-inventree-info'),
|
||||||
|
|
||||||
|
# Unknown endpoint
|
||||||
|
url(r'^.*$', NotFoundView.as_view(), name='api-404'),
|
||||||
]
|
]
|
||||||
|
|
||||||
settings_urls = [
|
settings_urls = [
|
||||||
|
@ -5,8 +5,8 @@ from . import api
|
|||||||
user_urls = [
|
user_urls = [
|
||||||
url(r'^(?P<pk>[0-9]+)/?$', api.UserDetail.as_view(), name='user-detail'),
|
url(r'^(?P<pk>[0-9]+)/?$', api.UserDetail.as_view(), name='user-detail'),
|
||||||
|
|
||||||
url(r'roles', api.RoleDetails.as_view(), name='api-user-roles'),
|
url(r'roles/?$', api.RoleDetails.as_view(), name='api-user-roles'),
|
||||||
url(r'token', api.GetAuthToken.as_view(), name='api-token'),
|
url(r'token/?$', api.GetAuthToken.as_view(), name='api-token'),
|
||||||
|
|
||||||
url(r'^$', api.UserList.as_view()),
|
url(r'^$', api.UserList.as_view()),
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user