Ejemplo n.º 1
0
def handle_app_error(exc_args):
    msg = str(exc_args[0]).lower()
    if msg.startswith('request_backlog'):
        return dbexceptions.RequestBacklog(exc_args)
    match = _errno_pattern.search(msg)
    if match:
        mysql_errno = int(match.group(1))
        # Prune the error message to truncate the query string
        # returned by mysql as it contains bind variables.
        if mysql_errno == 1062:
            parts = _errno_pattern.split(msg)
            pruned_msg = msg[:msg.find(parts[2])]
            new_args = (pruned_msg, ) + tuple(exc_args[1:])
            return dbexceptions.IntegrityError(new_args)
    return dbexceptions.DatabaseError(exc_args)
Ejemplo n.º 2
0
def convert_exception(exc, *args):
    new_args = exc.args + args
    if isinstance(exc, gorpc.TimeoutError):
        return dbexceptions.TimeoutError(new_args)
    elif isinstance(exc, gorpc.AppError):
        msg = str(exc[0]).lower()
        if msg.startswith('request_backlog'):
            return dbexceptions.RequestBacklog(new_args)
        match = _errno_pattern.search(msg)
        if match:
            mysql_errno = int(match.group(1))
            if mysql_errno == 1062:
                return dbexceptions.IntegrityError(new_args)
        return dbexceptions.DatabaseError(new_args)
    elif isinstance(exc, gorpc.ProgrammingError):
        return dbexceptions.ProgrammingError(new_args)
    elif isinstance(exc, gorpc.GoRpcError):
        return dbexceptions.FatalError(new_args)
    return exc