Skip to content

Commit 73d8a2b

Browse files
Merge branch 'master' of git://github.com/cguethle/django-rest-framework into cguethle-master
2 parents 2ecd984 + 7a87893 commit 73d8a2b

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

rest_framework/exceptions.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,55 +13,48 @@ class APIException(Exception):
1313
Base class for REST framework exceptions.
1414
Subclasses should provide `.status_code` and `.detail` properties.
1515
"""
16-
pass
16+
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
17+
default_detail = ""
18+
19+
def __init__(self, detail=None, status_code=None):
20+
self.status_code = status_code or self.status_code
21+
self.detail = detail or self.default_detail
1722

1823

1924
class ParseError(APIException):
2025
status_code = status.HTTP_400_BAD_REQUEST
2126
default_detail = 'Malformed request.'
2227

23-
def __init__(self, detail=None):
24-
self.detail = detail or self.default_detail
25-
2628

2729
class AuthenticationFailed(APIException):
2830
status_code = status.HTTP_401_UNAUTHORIZED
2931
default_detail = 'Incorrect authentication credentials.'
3032

31-
def __init__(self, detail=None):
32-
self.detail = detail or self.default_detail
33-
3433

3534
class NotAuthenticated(APIException):
3635
status_code = status.HTTP_401_UNAUTHORIZED
3736
default_detail = 'Authentication credentials were not provided.'
3837

39-
def __init__(self, detail=None):
40-
self.detail = detail or self.default_detail
41-
4238

4339
class PermissionDenied(APIException):
4440
status_code = status.HTTP_403_FORBIDDEN
4541
default_detail = 'You do not have permission to perform this action.'
4642

47-
def __init__(self, detail=None):
48-
self.detail = detail or self.default_detail
49-
5043

5144
class MethodNotAllowed(APIException):
5245
status_code = status.HTTP_405_METHOD_NOT_ALLOWED
5346
default_detail = "Method '%s' not allowed."
5447

5548
def __init__(self, method, detail=None):
56-
self.detail = (detail or self.default_detail) % method
49+
super(MethodNotAllowed, self).__init__((detail or self.default_detail) % method)
5750

5851

5952
class NotAcceptable(APIException):
6053
status_code = status.HTTP_406_NOT_ACCEPTABLE
6154
default_detail = "Could not satisfy the request's Accept header"
6255

6356
def __init__(self, detail=None, available_renderers=None):
64-
self.detail = detail or self.default_detail
57+
super(NotAcceptable, self).__init__(detail)
6558
self.available_renderers = available_renderers
6659

6760

@@ -70,19 +63,19 @@ class UnsupportedMediaType(APIException):
7063
default_detail = "Unsupported media type '%s' in request."
7164

7265
def __init__(self, media_type, detail=None):
73-
self.detail = (detail or self.default_detail) % media_type
66+
super(UnsupportedMediaType, self).__init__((detail or self.default_detail) % media_type)
7467

7568

7669
class Throttled(APIException):
7770
status_code = status.HTTP_429_TOO_MANY_REQUESTS
78-
default_detail = "Request was throttled."
71+
default_detail = 'Request was throttled.'
7972
extra_detail = "Expected available in %d second%s."
8073

8174
def __init__(self, wait=None, detail=None):
75+
super(Throttled, self).__init__(detail)
76+
8277
import math
8378
self.wait = wait and math.ceil(wait) or None
8479
if wait is not None:
85-
format = detail or self.default_detail + self.extra_detail
86-
self.detail = format % (self.wait, self.wait != 1 and 's' or '')
87-
else:
88-
self.detail = detail or self.default_detail
80+
format = self.detail + self.extra_detail
81+
self.detail = format % (self.wait, self.wait != 1 and 's' or '')

0 commit comments

Comments
 (0)