diff --git a/Source/API/script/Config/ConnectClass.php b/Source/API/script/Config/ConnectClass.php index 8b397c1..feaa2b9 100644 --- a/Source/API/script/Config/ConnectClass.php +++ b/Source/API/script/Config/ConnectClass.php @@ -23,8 +23,8 @@ class ConnectClass{ try { echo $this->dsn." ".$this->login." ".$this->password; $connection = new Connection($this->dsn,$this->login,$this->password); - }catch (PDOException){ - throw new PDOException(); + }catch (PDOException $e){ + throw new PDOException($e->getMessage(), $e->getCode(), $e); } return $connection; } diff --git a/Source/API/script/ExceptionHandle/PDOError.php b/Source/API/script/ExceptionHandle/PDOError.php index 2db529f..63a9b79 100644 --- a/Source/API/script/ExceptionHandle/PDOError.php +++ b/Source/API/script/ExceptionHandle/PDOError.php @@ -10,11 +10,10 @@ class PDOError extends HttpSpecializedException { protected $code = 408; protected string $title = "PDO connection failed"; - protected $message = "The connection method throw a PDO Exception, connection to database failed"; - public function __construct(ServerRequestInterface $request,?Throwable $previous = null) + public function __construct(ServerRequestInterface $request,string $message, ?Throwable $previous = null) { - parent::__construct($request, $this->message, $previous); + parent::__construct($request, $message,$previous); } } \ No newline at end of file diff --git a/Source/API/script/Gateway/GatewayForm.php b/Source/API/script/Gateway/GatewayForm.php index 2353732..ef94ce3 100644 --- a/Source/API/script/Gateway/GatewayForm.php +++ b/Source/API/script/Gateway/GatewayForm.php @@ -16,8 +16,7 @@ class GatewayForm try{ $this->connection = (new ConnectClass)->connect(); }catch(PDOException $e){ - echo $e->getMessage()." ET "; - throw new PDOException(); + throw new PDOException($e->getMessage(), $e->getCode(), $e); } } diff --git a/Source/API/script/index.php b/Source/API/script/index.php index bfa8710..6d200b8 100644 --- a/Source/API/script/index.php +++ b/Source/API/script/index.php @@ -45,9 +45,8 @@ $app->get('/', function (Request $request, Response $response) { $ok = true; $response->getBody()->write(json_encode((new $gateway)->$method($parameters))); } - }catch (PDOException){ - echo "ici?"; - throw new PDOError($request); + }catch (PDOException $e){ + throw new PDOError($request,$e->getMessage(),$e); } } if (!$ok){