From b3e29d9576f1b1b6d12f9abfeb4a06f669b45202 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 14 Sep 2012 22:42:29 +0100 Subject: Moved content negotiation out of response. Nicer exception handling now. --- djangorestframework/exceptions.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'djangorestframework/exceptions.py') diff --git a/djangorestframework/exceptions.py b/djangorestframework/exceptions.py index 3f5b23f6..6930515d 100644 --- a/djangorestframework/exceptions.py +++ b/djangorestframework/exceptions.py @@ -39,6 +39,15 @@ class MethodNotAllowed(APIException): self.detail = (detail or self.default_detail) % method +class NotAcceptable(APIException): + status_code = status.HTTP_406_NOT_ACCEPTABLE + default_detail = "Could not satisfy the request's Accept header" + + def __init__(self, detail=None, available_renderers=None): + self.detail = detail or self.default_detail + self.available_renderers = available_renderers + + class UnsupportedMediaType(APIException): status_code = status.HTTP_415_UNSUPPORTED_MEDIA_TYPE default_detail = "Unsupported media type '%s' in request." -- cgit v1.2.3 From a96211d3d1ba246512af5e32c31726a666c467ac Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Sun, 16 Sep 2012 21:48:55 +0100 Subject: Simplify negotiation. Drop MSIE hacks. Etc. --- djangorestframework/exceptions.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'djangorestframework/exceptions.py') diff --git a/djangorestframework/exceptions.py b/djangorestframework/exceptions.py index 6930515d..a405a885 100644 --- a/djangorestframework/exceptions.py +++ b/djangorestframework/exceptions.py @@ -31,6 +31,14 @@ class PermissionDenied(APIException): self.detail = detail or self.default_detail +class InvalidFormat(APIException): + status_code = status.HTTP_404_NOT_FOUND + default_detail = "Format suffix '.%s' not found." + + def __init__(self, format, detail=None): + self.detail = (detail or self.default_detail) % format + + class MethodNotAllowed(APIException): status_code = status.HTTP_405_METHOD_NOT_ALLOWED default_detail = "Method '%s' not allowed." -- cgit v1.2.3