Add error handling for MongoDB connection failure in Client class

This commit is contained in:
shimon committed 2025-08-03 10:06:14 +03:00
1 parent ff66361916
commit fba2c96b6e
1 file changed
+5 -2
+5 -2
View File
@@ -118,8 +118,11 @@ class Client
if ($this->client->isConnected()) {
return $this;
}
if(!$this->client->connect($this->host, $this->port)){
throw new \Exception("Failed to connect to MongoDB");
}
$this->client->connect($this->host, $this->port);
[$payload, $db] = $this->auth->start();
$res = $this->query($payload, $db);
@@ -934,4 +937,4 @@ class Client
$this->replicaSet = property_exists($result, 'setName');
return $this->replicaSet;
}
}
}