mirror of
https://github.com/ansible/awx.git
synced 2026-03-11 22:49:32 -02:30
Handle exception with invalid HTTP content_type.
Signed-off-by: Yunfan Zhang <yz322@duke.edu>
This commit is contained in:
@@ -23,7 +23,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from django.contrib.auth import views as auth_views
|
||||
|
||||
# Django REST Framework
|
||||
from rest_framework.exceptions import PermissionDenied, AuthenticationFailed, ParseError, NotAcceptable
|
||||
from rest_framework.exceptions import PermissionDenied, AuthenticationFailed, ParseError, NotAcceptable, UnsupportedMediaType
|
||||
from rest_framework import generics
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
@@ -197,6 +197,10 @@ class APIView(views.APIView):
|
||||
except (PermissionDenied, ParseError) as exc:
|
||||
request.drf_request_user = None
|
||||
self.__init_request_error__ = exc
|
||||
except UnsupportedMediaType as exc:
|
||||
exc.detail = _('You did not use correct content_type in your HTTP request. \
|
||||
If you are using our REST API, the content_type must be application/json')
|
||||
self.__init_request_error__ = exc
|
||||
return drf_request
|
||||
|
||||
def finalize_response(self, request, response, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user