'meta': { 'status': 'error', 'status_code': e.status_code, 'error_message': unicode(e) } } except InvalidMethod, e: status_code = 405 resp_envelope = { 'meta': { 'status': 'error', 'status_code': 405, 'error_message': '%s Invalid method should be one of %s' % (request.method, methods) } } except Exception, e: raise status_code = 500 resp_envelope = { 'meta': { 'status': 'error', 'status_code': 500, 'error_message': 'unhandled error' } } resp_json = json_dumps.encode(resp_envelope) return HttpResponse(resp_json, content_type='application/json', status=status_code)
'status_code': status_code, 'error_message': unicode(e) } } except Exception, e: raise status_code = 500 resp_envelope = { 'meta': { 'status': 'error', 'status_code': 500, 'error_message': 'unhandled error' } } resp_json = json_dumps.encode(resp_envelope) return make_response(resp_json, status_code, { 'Content-Type': 'application/json', }) def json_handler(schema=None): def outer_wraper(f): @functools.wraps(f) def wrapper(schema=None, *args, **kwargs): print f print schema return api_func(f, schema, *args, **kwargs) return wrapper
def serialize(self): data = self.to_dict() return json_dumps.encode(data)