Reputation: 251
What is best way to return extra data such as error code in error type response. #Method 1 does not carry extra info while #Method 2 doesnt work.
#method 1
ImmediateHttpResponse(HttpBadRequest('error')) #cant carry extra info
#method 2
class ErrorInfo(object):
msg_id = ''
msg_code = ''
msg_content = ''
class Resource(Resource):
....
def get_object_list(self, request):
if ...:
error_info = ErrorInfo()
error_info.msg_id = 'rt'
error_info.msg_code = 'rerer'
obj = {'objects': error_info}
return self.create_response(request, obj)
Upvotes: 0
Views: 133
Reputation: 33420
If it helps, you can use ImmediateHttpResponse(HttpResquest([...], status=403))
Upvotes: 1