mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 09:43:13 +08:00
Converted DeleteShortUrlException into a problem details exception
This commit is contained in:
@@ -4,12 +4,20 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Exception;
|
||||
|
||||
use Fig\Http\Message\StatusCodeInterface;
|
||||
use Throwable;
|
||||
use Zend\ProblemDetails\Exception\CommonProblemDetailsExceptionTrait;
|
||||
use Zend\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
class DeleteShortUrlException extends RuntimeException
|
||||
class DeleteShortUrlException extends DomainException implements ProblemDetailsExceptionInterface
|
||||
{
|
||||
use CommonProblemDetailsExceptionTrait;
|
||||
|
||||
private const TITLE = 'Cannot delete short URL';
|
||||
public const TYPE = 'INVALID_SHORTCODE_DELETION'; // FIXME Should be INVALID_SHORT_URL_DELETION
|
||||
|
||||
/** @var int */
|
||||
private $visitsThreshold;
|
||||
|
||||
@@ -21,11 +29,19 @@ class DeleteShortUrlException extends RuntimeException
|
||||
|
||||
public static function fromVisitsThreshold(int $threshold, string $shortCode): self
|
||||
{
|
||||
return new self($threshold, sprintf(
|
||||
$e = new self($threshold, sprintf(
|
||||
'Impossible to delete short URL with short code "%s" since it has more than "%s" visits.',
|
||||
$shortCode,
|
||||
$threshold
|
||||
));
|
||||
|
||||
$e->detail = $e->getMessage();
|
||||
$e->title = self::TITLE;
|
||||
$e->type = self::TYPE;
|
||||
$e->status = StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY;
|
||||
$e->additional = ['threshold' => $threshold];
|
||||
|
||||
return $e;
|
||||
}
|
||||
|
||||
public function getVisitsThreshold(): int
|
||||
|
||||
Reference in New Issue
Block a user