This commit is contained in:
Dennis Eichhorn 2017-09-08 19:30:56 +02:00
parent 0c157cddf6
commit c2e5dd8105
2 changed files with 26 additions and 4 deletions

View File

@ -113,7 +113,10 @@ abstract class SettingsAbstract implements OptionsInterface
return $options; return $options;
} catch (\PDOException $e) { } catch (\PDOException $e) {
// todo does it mean that the recognition isn't here but at the place where the new happens? // 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);
} }
} }

View File

@ -37,7 +37,7 @@ class DatabaseExceptionFactory
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function create(\PDOException $e) : \PDOException public static function createException(\PDOException $e) : \PDOException
{ {
switch ($e->getCode()) { switch ($e->getCode()) {
case '42S02': 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. * Create table exception.
* *
@ -56,8 +75,8 @@ class DatabaseExceptionFactory
* *
* @since 1.0.0 * @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());
} }
} }