'Process a query or command operation failure'

def handleOperationFailure(self, hostKey, operation, exception):

    try:
        msg = {}
        exceptionStr = traceback.format_exc(exception)
        if (exceptionStr.find('unrecognized    command:') > (-1)):
            return
        if (exceptionStr.find('failed:    not    running    with    --replSet') > (-1)):
            return
        if (exceptionStr.find('failed:    ns    not    found') > (-1)):
            return
        if (exceptionStr.find('not    master    or    secondary') > (-1)):
            return
        msg['hostnameAndPort'] = hostKey
        msg['operation'] = operation
        msg['exception'] = exceptionStr
        res = None
        try:
            res = urllib2.urlopen(self.operationFailureUrl, bson.binary.Binary(bson.BSON.encode(msg, check_keys=False)))
            res.read()
        finally:
            if (res is not None):
                res.close()
    except:
        pass
