def fail(md): if md.get("code") == "Neo.ClientError.Procedure.ProcedureNotFound": raise BoltRoutingError("Server does not support routing", address) else: raise BoltRoutingError("Routing support broken on server", address)
def fail(md): from neo4j._exceptions import BoltRoutingError if md.get("code") == "Neo.ClientError.Procedure.ProcedureNotFound": raise BoltRoutingError("Server does not support routing", self.unresolved_address) else: raise BoltRoutingError("Routing support broken on server", self.unresolved_address)
def fail(md): from neo4j._exceptions import BoltRoutingError code = md.get("code") if code == "Neo.ClientError.Database.DatabaseNotFound": return # surface this error to the user elif code == "Neo.ClientError.Procedure.ProcedureNotFound": raise BoltRoutingError("Server does not support routing", self.unresolved_address) else: raise BoltRoutingError("Routing support broken on server", self.unresolved_address)
def fetch_routing_table(self, *, address, timeout, database): """ Fetch a routing table from a given router address. :param address: router address :param timeout: seconds :param database: the database name :type: str :return: a new RoutingTable instance or None if the given router is currently unable to provide routing information :raise neo4j.exceptions.ServiceUnavailable: if no writers are available :raise neo4j._exceptions.BoltProtocolError: if the routing information received is unusable """ new_routing_info = self.fetch_routing_info(address=address, timeout=timeout, database=database) if new_routing_info is None: return None elif not new_routing_info: raise BoltRoutingError("Invalid routing table", address) else: servers = new_routing_info[0]["servers"] ttl = new_routing_info[0]["ttl"] new_routing_table = RoutingTable.parse_routing_info( database=database, servers=servers, ttl=ttl) # Parse routing info and count the number of each type of server num_routers = len(new_routing_table.routers) num_readers = len(new_routing_table.readers) # num_writers = len(new_routing_table.writers) # If no writers are available. This likely indicates a temporary state, # such as leader switching, so we should not signal an error. # No routers if num_routers == 0: raise BoltRoutingError("No routing servers returned from server", address) # No readers if num_readers == 0: raise BoltRoutingError("No read servers returned from server", address) # At least one of each is fine, so return this table return new_routing_table