Skip to content

Commit 53cbd08

Browse files
authored
Surface DatabaseNotFound on routing message to user (#519)
* Surface DatabaseNotFound on routing message to user * Adjust test to reflect surfacing DatabaseNotFound error
1 parent e3c9d4d commit 53cbd08

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

neo4j/io/_bolt4.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ def route(self, database):
164164

165165
def fail(md):
166166
from neo4j._exceptions import BoltRoutingError
167-
if md.get("code") == "Neo.ClientError.Procedure.ProcedureNotFound":
167+
code = md.get("code")
168+
if code == "Neo.ClientError.Database.DatabaseNotFound":
169+
return # surface this error to the user
170+
elif code == "Neo.ClientError.Procedure.ProcedureNotFound":
168171
raise BoltRoutingError("Server does not support routing", self.unresolved_address)
169172
else:
170173
raise BoltRoutingError("Routing support broken on server", self.unresolved_address)
@@ -512,7 +515,10 @@ def route(self, database):
512515

513516
def fail(md):
514517
from neo4j._exceptions import BoltRoutingError
515-
if md.get("code") == "Neo.ClientError.Procedure.ProcedureNotFound":
518+
code = md.get("code")
519+
if code == "Neo.ClientError.Database.DatabaseNotFound":
520+
return # surface this error to the user
521+
elif code == "Neo.ClientError.Procedure.ProcedureNotFound":
516522
raise BoltRoutingError("Server does not support routing", self.unresolved_address)
517523
else:
518524
raise BoltRoutingError("Routing support broken on server", self.unresolved_address)

tests/integration/test_neo4j_driver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def test_test_multi_db_specify_database(neo4j_uri, auth, target):
8181
assert "Database name parameter for selecting database is not supported in Bolt Protocol Version(3, 0)." in error.args[0]
8282
except ClientError as error:
8383
# FAILURE {'code': 'Neo.ClientError.Database.DatabaseNotFound' - This message is sent from the server
84-
assert error.args[0] == "Unable to get a routing table for database 'test_database' because this database does not exist"
84+
assert error.code == "Neo.ClientError.Database.DatabaseNotFound"
85+
assert "test_database" in error.message
8586

8687

8788
def test_neo4j_multi_database_support_create(neo4j_uri, auth, target, requires_bolt_4x):

0 commit comments

Comments
 (0)