返回错误类型响应中错误代码等额外数据的最佳方式是什么? #方法1不会携带额外的信息,而#方法2不起作用。在错误响应中携带额外信息
#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)
界定 '携带额外的信息'。 – jpic 2012-02-29 12:11:42