Пример #1
0
def handle_invalid(exc):
    format = response_format(app, request)
    if format == 'json':
        body = {'status': 400,
                'name': 'Invalid Data',
                'description': unicode(exc),
                'errors': exc.unpack_errors()}
        return jsonify(body, status=400)
    return Response(repr(exc.unpack_errors()), status=400, 
                    mimetype='text/plain')
Пример #2
0
def handle_exceptions(exc):
    """ Re-format exceptions to JSON if accept requires that. """
    format = response_format(app, request)
    if format == 'json':
        body = {'status': exc.code,
                'name': exc.name,
                'description': exc.get_description(request.environ)}
        return jsonify(body, status=exc.code,
                       headers=exc.get_headers(request.environ))
    return exc
Пример #3
0
def handle_invalid(exc):
    format = response_format(app, request)
    if format == 'json':
        body = {
            'status': 400,
            'name': 'Invalid Data',
            'description': unicode(exc),
            'errors': exc.unpack_errors()
        }
        return jsonify(body, status=400)
    return Response(repr(exc.unpack_errors()),
                    status=400,
                    mimetype='text/plain')
Пример #4
0
def handle_exceptions(exc):
    """ Re-format exceptions to JSON if accept requires that. """
    format = response_format(app, request)
    if format == 'json':
        body = {
            'status': exc.code,
            'name': exc.name,
            'description': exc.get_description(request.environ)
        }
        return jsonify(body,
                       status=exc.code,
                       headers=exc.get_headers(request.environ))
    return exc