import logging


def mongo_filter_errors(obj, converter):
    """Call converter on obj and ignore failed objects.

    Returns result of converter. If converter raises Exception, None will be
    returned.
    If obj is list, converter is called on each element. Those which raise
    exceptions are skipped.
    """
    if obj is None:
        return None
    try:
        return converter(obj)
    except Exception as error:
        logging.error("During parsing db data (single): %s", error)
        logging.error("Method %s", converter)
        logging.error("Value %s", obj)
        return None