mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-10 17:23:12 +08:00
Added domain to DeleteShortUrlException
This commit is contained in:
@@ -7,6 +7,7 @@ namespace Shlinkio\Shlink\Core\Exception;
|
||||
use Fig\Http\Message\StatusCodeInterface;
|
||||
use Mezzio\ProblemDetails\Exception\CommonProblemDetailsExceptionTrait;
|
||||
use Mezzio\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
|
||||
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
@@ -17,11 +18,15 @@ class DeleteShortUrlException extends DomainException implements ProblemDetailsE
|
||||
private const TITLE = 'Cannot delete short URL';
|
||||
private const TYPE = 'INVALID_SHORTCODE_DELETION'; // FIXME Deprecated: Should be INVALID_SHORT_URL_DELETION
|
||||
|
||||
public static function fromVisitsThreshold(int $threshold, string $shortCode): self
|
||||
public static function fromVisitsThreshold(int $threshold, ShortUrlIdentifier $identifier): self
|
||||
{
|
||||
$shortCode = $identifier->shortCode();
|
||||
$domain = $identifier->domain();
|
||||
$suffix = $domain === null ? '' : sprintf(' for domain "%s"', $domain);
|
||||
$e = new self(sprintf(
|
||||
'Impossible to delete short URL with short code "%s" since it has more than "%s" visits.',
|
||||
'Impossible to delete short URL with short code "%s"%s, since it has more than "%s" visits.',
|
||||
$shortCode,
|
||||
$suffix,
|
||||
$threshold,
|
||||
));
|
||||
|
||||
@@ -34,6 +39,10 @@ class DeleteShortUrlException extends DomainException implements ProblemDetailsE
|
||||
'threshold' => $threshold,
|
||||
];
|
||||
|
||||
if ($domain !== null) {
|
||||
$e->additional['domain'] = $domain;
|
||||
}
|
||||
|
||||
return $e;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user