human
Complete this python program:
def catch_integrity_errors(session):
assistant
#Here is the Python code you requested.

    """Returns a decorator that catches database integrity errors.
    `session` is the SQLAlchemy session in which all database transactions will
    be performed.
    View methods can be wrapped like this::
    @catch_integrity_errors(session)
    def get(self, *args, **kw):
    return \...\
    Specifically, functions wrapped with the returned decorator catch the
    exceptions specified in :data:`ROLLBACK_ERRORS`. After the exceptions are
    caught, the session is rolled back, the exception is logged on the current
    Flask application, and an error response is returned to the client.
    """
    def decorated(func):
        'Returns    a    decorated    version    of    ``func``,    as    described    in    the\n                                wrapper    defined    within.\n\n                                '
        @wraps(func)
        def wrapped(*args, **kw):
            'Executes    ``func(*args,    **kw)``    but    catches    any    exception\n                                                that    warrants    a    database    rollback.\n\n                                                '
            try:
                return func(*args, **kw)
            except SQLAlchemyError as exception:
                session.rollback()
                status = (409 if is_conflict(exception) else 400)
                detail = str(exception)
                title = un_camel_case(exception.__class__.__name__)
                return error_response(status, cause=exception, detail=detail, title=title)
        return wrapped
    return decorated