def catch_integrity_errors(session):
 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

def catch_integrity_errors ( session ) : def decorated ( func ) : @ wraps ( func ) def wrapped ( * args , ** kw ) : 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
returns a decorator that catches database integrity errors .