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

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace Nsq\Exception;
use RuntimeException;
use Throwable;
final class ConnectionFail extends RuntimeException implements NsqException
{
public static function fromThrowable(Throwable $throwable): self
{
return new self($throwable->getMessage(), (int) $throwable->getCode(), $throwable);
}
}

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Nsq\Exception;
use Nsq\Message;
use RuntimeException;
final class MessageAlreadyFinished extends RuntimeException implements NsqException
{
public static function finish(Message $message): self
{
return new self('Can\'t finish message as it already finished.');
}
public static function requeue(Message $message): self
{
return new self('Can\'t requeue message as it already finished.');
}
public static function touch(Message $message): self
{
return new self('Can\'t touch message as it already finished.');
}
}

View File

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace Nsq\Exception;
use RuntimeException;
final class NsqError extends RuntimeException implements NsqException
{
}

View File

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace Nsq\Exception;
use Throwable;
interface NsqException extends Throwable
{
}

View File

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace Nsq\Exception;
use RuntimeException;
final class UnexpectedResponse extends RuntimeException implements NsqException
{
}