Add more specific exceptions

This commit is contained in:
2021-01-24 18:39:26 +03:00
parent 92e8ca0812
commit caa1bab9b5
13 changed files with 98 additions and 29 deletions

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Nsq;
use Nsq\Exception\MessageAlreadyFinished;
final class Message
{
/**
@ -48,7 +50,7 @@ final class Message
public function finish(): void
{
if ($this->finished) {
throw new Exception('Can\'t finish message as it already finished.');
throw MessageAlreadyFinished::finish($this);
}
$this->consumer->fin($this->id);
@ -58,7 +60,7 @@ final class Message
public function requeue(int $timeout): void
{
if ($this->finished) {
throw new Exception('Can\'t requeue message as it already finished.');
throw MessageAlreadyFinished::requeue($this);
}
$this->consumer->req($this->id, $timeout);
@ -68,7 +70,7 @@ final class Message
public function touch(): void
{
if ($this->finished) {
throw new Exception('Can\'t touch message as it already finished.');
throw MessageAlreadyFinished::touch($this);
}
$this->consumer->touch($this->id);