Remove 405 method not allowed ImmediateResponse

This commit is contained in:
Tom Christie 2012-08-26 22:13:26 +01:00
parent 3928802178
commit 474780f9d6
3 changed files with 16 additions and 13 deletions

View File

@ -17,12 +17,20 @@ class PermissionDenied(Exception):
self.detail = detail or self.default_detail
class UnsupportedMediaType(Exception):
status_code = 415
default_detail = 'Unsupported media type in request'
class MethodNotAllowed(Exception):
status_code = status.HTTP_405_METHOD_NOT_ALLOWED
default_detail = "Method '%s' not allowed"
def __init__(self, detail=None):
self.detail = detail or self.default_detail
def __init__(self, method, detail):
self.detail = (detail or self.default_detail) % method
class UnsupportedMediaType(Exception):
status_code = status.HTTP_415_UNSUPPORTED_MEDIA_TYPE
default_detail = "Unsupported media type '%s' in request"
def __init__(self, media_type, detail=None):
self.detail = (detail or self.default_detail) % media_type
# class Throttled(Exception):
# def __init__(self, detail):

View File

@ -207,8 +207,7 @@ class Request(object):
"""
Parse the request content.
May raise a 415 ImmediateResponse (Unsupported Media Type), or a
400 ImmediateResponse (Bad Request).
May raise an `UnsupportedMediaType`, or `ParseError` exception.
"""
if self.stream is None or self.content_type is None:
return (None, None)
@ -217,8 +216,7 @@ class Request(object):
if parser.can_handle_request(self.content_type):
return parser.parse(self.stream, self.META, self.upload_handlers)
raise UnsupportedMediaType("Unsupported media type in request '%s'" %
self._content_type)
raise UnsupportedMediaType(self._content_type)
def _authenticate(self):
"""

View File

@ -147,10 +147,7 @@ class View(DjangoView):
Return an HTTP 405 error if an operation is called which does not have
a handler method.
"""
content = {
'detail': "Method '%s' not allowed." % request.method
}
raise ImmediateResponse(content, status.HTTP_405_METHOD_NOT_ALLOWED)
raise exceptions.MethodNotAllowed(request.method)
@property
def _parsed_media_types(self):