6
6
"""
7
7
from __future__ import unicode_literals
8
8
from rest_framework import status
9
+ import math
9
10
10
11
11
12
class APIException (Exception ):
@@ -14,10 +15,9 @@ class APIException(Exception):
14
15
Subclasses should provide `.status_code` and `.detail` properties.
15
16
"""
16
17
status_code = status .HTTP_500_INTERNAL_SERVER_ERROR
17
- default_detail = ""
18
+ default_detail = ''
18
19
19
- def __init__ (self , detail = None , status_code = None ):
20
- self .status_code = status_code or self .status_code
20
+ def __init__ (self , detail = None ):
21
21
self .detail = detail or self .default_detail
22
22
23
23
@@ -46,15 +46,15 @@ class MethodNotAllowed(APIException):
46
46
default_detail = "Method '%s' not allowed."
47
47
48
48
def __init__ (self , method , detail = None ):
49
- super ( MethodNotAllowed , self ). __init__ (( detail or self .default_detail ) % method )
49
+ self . detail = ( detail or self .default_detail ) % method
50
50
51
51
52
52
class NotAcceptable (APIException ):
53
53
status_code = status .HTTP_406_NOT_ACCEPTABLE
54
54
default_detail = "Could not satisfy the request's Accept header"
55
55
56
56
def __init__ (self , detail = None , available_renderers = None ):
57
- super ( NotAcceptable , self ). __init__ ( detail )
57
+ self . detail = detail or self . default_detail
58
58
self .available_renderers = available_renderers
59
59
60
60
@@ -63,7 +63,7 @@ class UnsupportedMediaType(APIException):
63
63
default_detail = "Unsupported media type '%s' in request."
64
64
65
65
def __init__ (self , media_type , detail = None ):
66
- super ( UnsupportedMediaType , self ). __init__ (( detail or self .default_detail ) % media_type )
66
+ self . detail = ( detail or self .default_detail ) % media_type
67
67
68
68
69
69
class Throttled (APIException ):
@@ -72,10 +72,10 @@ class Throttled(APIException):
72
72
extra_detail = "Expected available in %d second%s."
73
73
74
74
def __init__ (self , wait = None , detail = None ):
75
- super ( Throttled , self ). __init__ ( detail )
76
-
77
- import math
78
- self . wait = wait and math . ceil ( wait ) or None
79
- if wait is not None :
80
- format = self . detail + self . extra_detail
81
- self .detail = format % ( self . wait , self . wait != 1 and 's' or '' )
75
+ if wait is None :
76
+ self . detail = detail or self . default_detail
77
+ self . wait = None
78
+ else :
79
+ format = ( detail or self . default_detail ) + self . extra_detail
80
+ self . detail = format % ( wait , wait != 1 and 's' or '' )
81
+ self .wait = math . ceil ( wait )
0 commit comments