Added domain to DeleteShortUrlException

This commit is contained in:
Alejandro Celaya
2021-11-30 21:37:35 +01:00
parent cdab1e9cae
commit a66ddabe8a
7 changed files with 51 additions and 11 deletions

View File

@@ -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;
}