diff --git a/src/Driver/Cassandra/CassandraModelException.php b/src/Driver/Cassandra/CassandraModelException.php index 174b697..caac9e6 100644 --- a/src/Driver/Cassandra/CassandraModelException.php +++ b/src/Driver/Cassandra/CassandraModelException.php @@ -2,10 +2,10 @@ namespace Aternos\Model\Driver\Cassandra; -use Aternos\Model\WrappingModelException; +use Aternos\Model\ModelException; use Throwable; -class CassandraModelException extends WrappingModelException +class CassandraModelException extends ModelException { /** * Wrap an existing exception into a CassandraModelException diff --git a/src/WrappingModelException.php b/src/Driver/Redis/Exception/RedisConnectionException.php similarity index 52% rename from src/WrappingModelException.php rename to src/Driver/Redis/Exception/RedisConnectionException.php index be03e8e..69b6d89 100644 --- a/src/WrappingModelException.php +++ b/src/Driver/Redis/Exception/RedisConnectionException.php @@ -1,13 +1,16 @@ getMessage(), $exception->getCode(), $exception); } - - final protected function __construct(string $message, int $code = null, ?Throwable $previous = null) - { - parent::__construct($message, $code, $previous); - } } diff --git a/src/Driver/Redis/Exception/RedisModelException.php b/src/Driver/Redis/Exception/RedisModelException.php new file mode 100644 index 0000000..d574e21 --- /dev/null +++ b/src/Driver/Redis/Exception/RedisModelException.php @@ -0,0 +1,10 @@ +getLastError(); + if ($error !== false) { + throw new static("Redis Query Error: " . $error); + } + } +} diff --git a/src/Driver/Redis/Redis.php b/src/Driver/Redis/Redis.php index 97748ac..ef8b0d4 100644 --- a/src/Driver/Redis/Redis.php +++ b/src/Driver/Redis/Redis.php @@ -5,6 +5,9 @@ use Aternos\Model\Driver\Driver; use Aternos\Model\Driver\Features\CacheableInterface; use Aternos\Model\Driver\Features\CRUDAbleInterface; +use Aternos\Model\Driver\Redis\Exception\RedisConnectionException; +use Aternos\Model\Driver\Redis\Exception\RedisModelException; +use Aternos\Model\Driver\Redis\Exception\RedisQueryException; use Aternos\Model\ModelInterface; use RedisException; @@ -80,7 +83,7 @@ protected function connect(): void $this->connection->connect($this->socket); } } catch (RedisException $e) { - throw RedisModelException::wrapping($e); + throw RedisConnectionException::wrapping($e); } } } @@ -113,10 +116,12 @@ public function save(ModelInterface $model): bool $this->connect(); $key = $this->generateCacheKey($model::class, $model->getId()); try { - return $this->connection->set($key, json_encode($model), $model->getCacheTime()); + $this->connection->set($key, json_encode($model), $model->getCacheTime()); + RedisQueryException::checkConnection($this->connection); } catch (RedisException $e) { - throw RedisModelException::wrapping($e); + throw RedisConnectionException::wrapping($e); } + return true; } /** @@ -137,8 +142,9 @@ public function get(string $modelClass, mixed $id, ?ModelInterface $model = null $this->connect(); try { $rawData = $this->connection->get($this->generateCacheKey($modelClass, $id)); + RedisQueryException::checkConnection($this->connection); } catch (RedisException $e) { - throw RedisModelException::wrapping($e); + throw RedisConnectionException::wrapping($e); } if (!$rawData) { @@ -172,10 +178,12 @@ public function delete(ModelInterface $model): bool $this->connect(); $key = $this->generateCacheKey($model::class, $model->getId()); try { - return $this->connection->del($key); + $this->connection->del($key); + RedisQueryException::checkConnection($this->connection); } catch (RedisException $e) { - throw RedisModelException::wrapping($e); + throw RedisConnectionException::wrapping($e); } + return true; } /** diff --git a/src/Driver/Redis/RedisModelException.php b/src/Driver/Redis/RedisModelException.php deleted file mode 100644 index 17b05e0..0000000 --- a/src/Driver/Redis/RedisModelException.php +++ /dev/null @@ -1,10 +0,0 @@ -