diff --git a/Config/SettingsAbstract.php b/Config/SettingsAbstract.php index 39ca54f50..9b6a597de 100644 --- a/Config/SettingsAbstract.php +++ b/Config/SettingsAbstract.php @@ -113,7 +113,10 @@ abstract class SettingsAbstract implements OptionsInterface return $options; } catch (\PDOException $e) { // todo does it mean that the recognition isn't here but at the place where the new happens? - throw DatabaseExceptionFactory::create($e); + $exception = DatabaseExceptionFactory::createException($e); + $message = DatabaseExceptionFactory::createExceptionMessage($e); + + throw new $exception($message); } } diff --git a/DataStorage/Database/DatabaseExceptionFactory.php b/DataStorage/Database/DatabaseExceptionFactory.php index a4df4cec1..3348b22c6 100644 --- a/DataStorage/Database/DatabaseExceptionFactory.php +++ b/DataStorage/Database/DatabaseExceptionFactory.php @@ -37,7 +37,7 @@ class DatabaseExceptionFactory * * @since 1.0.0 */ - public static function create(\PDOException $e) : \PDOException + public static function createException(\PDOException $e) : \PDOException { switch ($e->getCode()) { case '42S02': @@ -47,6 +47,25 @@ class DatabaseExceptionFactory } } + /** + * Constructor. + * + * @param \PDOException $e Exception + * + * @return \PDOException + * + * @since 1.0.0 + */ + public static function createExceptionMessage(\PDOException $e) : \PDOException + { + switch ($e->getCode()) { + case '42S02': + return self::createTableViewExceptionMessage($e); + default: + return $e; + } + } + /** * Create table exception. * @@ -56,8 +75,8 @@ class DatabaseExceptionFactory * * @since 1.0.0 */ - private static function createTableViewException(\PDOException $e) : \PDOException + private static function createTableViewException(\PDOException $e) : string { - return new TableException(TableException::findTable($e->getMessage())); + return TableException::findTable($e->getMessage()); } }