@@ -7,16 +7,20 @@ class JsonApiException(Exception):
77 """Base exception class for unknown errors"""
88
99 title = 'Unknown error'
10- status = 500
10+ status = ' 500'
1111
12- def __init__ (self , source , detail , title = None , status = None ):
12+ def __init__ (self , source , detail , title = None , status = None , code = None , id_ = None , links = None , meta = None ):
1313 """Initialize a jsonapi exception
1414
1515 :param dict source: the source of the error
1616 :param str detail: the detail of the error
1717 """
1818 self .source = source
1919 self .detail = detail
20+ self .code = code
21+ self .id = id_
22+ self .links = links or {}
23+ self .meta = meta or {}
2024 if title is not None :
2125 self .title = title
2226 if status is not None :
@@ -27,14 +31,18 @@ def to_dict(self):
2731 return {'status' : self .status ,
2832 'source' : self .source ,
2933 'title' : self .title ,
30- 'detail' : self .detail }
34+ 'detail' : self .detail ,
35+ 'id' : self .id ,
36+ 'code' : self .code ,
37+ 'links' : self .links ,
38+ 'meta' : self .meta }
3139
3240
3341class BadRequest (JsonApiException ):
3442 """BadRequest error"""
3543
36- title = " Bad request"
37- status = 400
44+ title = ' Bad request'
45+ status = ' 400'
3846
3947
4048class InvalidField (BadRequest ):
@@ -56,7 +64,7 @@ class InvalidInclude(BadRequest):
5664 resource schema
5765 """
5866
59- title = " Invalid include querystring parameter."
67+ title = ' Invalid include querystring parameter.'
6068
6169 def __init__ (self , detail ):
6270 """Initialize InvalidInclude error instance
@@ -70,7 +78,7 @@ def __init__(self, detail):
7078class InvalidFilters (BadRequest ):
7179 """Error to warn that a specified filters in querystring parameter contains errors"""
7280
73- title = " Invalid filters querystring parameter."
81+ title = ' Invalid filters querystring parameter.'
7482
7583 def __init__ (self , detail ):
7684 """Initialize InvalidField error instance
@@ -84,7 +92,7 @@ def __init__(self, detail):
8492class InvalidSort (BadRequest ):
8593 """Error to warn that a field specified in sort querystring parameter is not in the requested resource schema"""
8694
87- title = " Invalid sort querystring parameter."
95+ title = ' Invalid sort querystring parameter.'
8896
8997 def __init__ (self , detail ):
9098 """Initialize InvalidField error instance
@@ -98,24 +106,24 @@ def __init__(self, detail):
98106class ObjectNotFound (JsonApiException ):
99107 """Error to warn that an object is not found in a database"""
100108
101- title = " Object not found"
102- status = 404
109+ title = ' Object not found'
110+ status = ' 404'
103111
104112
105113class RelatedObjectNotFound (ObjectNotFound ):
106114 """Error to warn that a related object is not found"""
107115
108- title = " Related object not found"
116+ title = ' Related object not found'
109117
110118
111119class RelationNotFound (JsonApiException ):
112120 """Error to warn that a relationship is not found on a model"""
113121
114- title = " Relation not found"
122+ title = ' Relation not found'
115123
116124
117125class InvalidType (JsonApiException ):
118126 """Error to warn that there is a conflit between resource types"""
119127
120- title = " Invalid type"
121- status = 409
128+ title = ' Invalid type'
129+ status = ' 409'
0 commit comments