Skip to content

Commit 7af969a

Browse files
author
root
committed
Refactor error handling to show clean authentication messages and hide technical details
1 parent dc481ec commit 7af969a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

vertica_python/vertica/connection.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import ssl
4545
import uuid
4646
import warnings
47+
import re
4748
from collections import deque
4849
from struct import unpack
4950

@@ -963,13 +964,21 @@ def send_startup(totp_value=None):
963964
self.backend_key = message.key
964965
elif isinstance(message, messages.ErrorResponse):
965966
error_msg = message.error_message()
966-
if "Invalid TOTP" in error_msg:
967+
968+
# Extract only the "Message: ..." part
969+
match = re.search(r'Message: (.+?)(?:, Sqlstate|$)', error_msg, re.DOTALL)
970+
short_msg = match.group(1).strip() if match else error_msg.strip()
971+
972+
if "Invalid TOTP" in short_msg:
973+
print("❌ Authentication failed: Invalid TOTP token.")
967974
self._logger.error("❌ Authentication failed: Invalid TOTP token.")
968975
self.close_socket()
969976
raise errors.ConnectionError("Authentication failed: Invalid TOTP token.")
977+
970978
# Generic error fallback
971-
self._logger.error(error_msg)
972-
raise errors.ConnectionError("❌ Authentication failed due to server error.")
979+
print(f"❌ Authentication failed: {short_msg}")
980+
self._logger.error(short_msg)
981+
raise errors.ConnectionError(f"❌ Authentication failed: {short_msg}")
973982
else:
974983
self._logger.warning(f"⚠️ Unexpected message type: {type(message).__name__}")
975984

0 commit comments

Comments
 (0)