issue-19: ajout de logs des exceptions PDOExceptions
All checks were successful
Cadoles/hydra-sql/pipeline/head This commit looks good
All checks were successful
Cadoles/hydra-sql/pipeline/head This commit looks good
This commit is contained in:
parent
ba63c271f9
commit
fe5ca83664
@ -6,18 +6,20 @@ use App\SQLLogin\SQLLoginConnect;
|
||||
use App\SQLLogin\SQLLoginRequest;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
class SQLLoginService extends AbstractController
|
||||
{
|
||||
public SQLLoginRequest $sqlLoginRequest;
|
||||
|
||||
public function __construct(SQLLoginRequest $sqlLoginRequest)
|
||||
public function __construct(SQLLoginRequest $sqlLoginRequest, private LoggerInterface $loggerInterface)
|
||||
{
|
||||
$this->sqlLoginRequest = $sqlLoginRequest;
|
||||
$this->loggerInterface = $loggerInterface;
|
||||
}
|
||||
|
||||
public function fetchDatas($login)
|
||||
public function fetchDatas($login): array
|
||||
{
|
||||
try {
|
||||
$dbh = $this->getConnection();
|
||||
@ -29,19 +31,14 @@ class SQLLoginService extends AbstractController
|
||||
$datas = $query->fetch(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
\Sentry\captureException($e);
|
||||
|
||||
$this->loggerInterface->critical($e->getMessage());
|
||||
throw new PDOException();
|
||||
}
|
||||
|
||||
return $datas;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $login
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function fetchPassword($login)
|
||||
public function fetchPassword($login): array|bool
|
||||
{
|
||||
try {
|
||||
$dbh = $this->getConnection();
|
||||
@ -50,7 +47,7 @@ class SQLLoginService extends AbstractController
|
||||
$query->execute([$this->sqlLoginRequest->getLoginColumnName() => $login]);
|
||||
$password = $query->fetch(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
\Sentry\captureException($e);
|
||||
$this->loggerInterface->critical($e->getMessage());
|
||||
throw new PDOException();
|
||||
}
|
||||
if ($password) {
|
||||
@ -63,7 +60,7 @@ class SQLLoginService extends AbstractController
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getConnection()
|
||||
public function getConnection(): PDO
|
||||
{
|
||||
// Appel du singleton
|
||||
$sqlLogin = SQLLoginConnect::getInstance();
|
||||
|
Loading…
Reference in New Issue
Block a user