@@ -37,29 +37,21 @@ public function getResponse(): Response
3737 try {
3838 $ response = $ this ->connection ->protocol ()->getResponse ();
3939 } catch (Throwable $ e ) {
40- // Convert socket timeout and I/O exceptions to Neo4jException
41- $ message = strtolower ($ e ->getMessage ());
42-
4340 if ($ this ->isTimeoutException ($ e )) {
44- // Extract timeout value from the exception message if available
4541 $ timeoutMsg = 'Connection timeout reached ' ;
46- if (preg_match ('/(\d+)\s*(?:milliseconds?|ms|seconds?|s)/ ' , $ e ->getMessage (), $ matches )) {
42+ if (preg_match ('/(\d+)\s*(?:milliseconds?|ms|seconds?|s)/ ' , $ e ->getMessage (), $ matches ) && array_key_exists ( 1 , $ matches ) ) {
4743 $ timeoutMsg = 'Connection timeout reached after ' .$ matches [1 ].' seconds ' ;
4844 }
49- // Close the connection to mark it as unusable
5045 try {
5146 $ this ->connection ->close ();
5247 } catch (Throwable ) {
53- // Ignore errors when closing a broken connection
5448 }
5549 // Use DriverError so the driver treats this as a failure
5650 throw new Neo4jException ([Neo4jError::fromMessageAndCode ('Neo.ClientError.Cluster.NotALeader ' , $ timeoutMsg )], $ e );
5751 } elseif ($ this ->isSocketException ($ e )) {
58- // Handle socket errors (broken pipe, connection reset, etc.)
5952 try {
6053 $ this ->connection ->close ();
6154 } catch (Throwable ) {
62- // Ignore errors when closing a broken connection
6355 }
6456 throw new Neo4jException ([Neo4jError::fromMessageAndCode ('Neo.ClientError.Cluster.NotALeader ' , 'Connection error: ' .$ e ->getMessage ())], $ e );
6557 }
0 commit comments