示例#1
0
文件: views.py 项目: Arunanandam/lark
            '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)
示例#2
0
文件: api.py 项目: krectra/lark
                '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
示例#3
0
    def serialize(self):

        data = self.to_dict()
        return json_dumps.encode(data)