Skip to content

Commit 19e3d42

Browse files
committed
Unauthorized error on init
1 parent 1cd78bd commit 19e3d42

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

neo4j/v1/bolt.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
from .constants import DEFAULT_USER_AGENT, KNOWN_HOSTS, MAGIC_PREAMBLE, TRUST_DEFAULT, TRUST_ON_FIRST_USE
4242
from .compat import hex2
43-
from .exceptions import ProtocolError
43+
from .exceptions import ProtocolError, Unauthorized
4444
from .packstream import Packer, Unpacker
4545
from .ssl_compat import SSL_AVAILABLE, HAS_SNI, SSLError
4646

@@ -230,7 +230,9 @@ def __init__(self, sock, **config):
230230
self.der_encoded_server_certificate = config.get("der_encoded_server_certificate")
231231

232232
def on_failure(metadata):
233-
raise ProtocolError(metadata.get("message", "INIT failed"))
233+
code = metadata.get("code")
234+
error = Unauthorized if code == "Neo.ClientError.Security.Unauthorized" else ProtocolError
235+
raise error(metadata.get("message", "INIT failed"))
234236

235237
response = Response(self)
236238
response.on_failure = on_failure

neo4j/v1/exceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class ProtocolError(Exception):
2424
"""
2525

2626

27+
class Unauthorized(Exception):
28+
""" Raised when an action is not permitted.
29+
"""
30+
31+
2732
class CypherError(Exception):
2833
""" Raised when the Cypher engine returns an error to the client.
2934
"""

0 commit comments

Comments
 (0)