mirror of
https://github.com/shlinkio/shlink.git
synced 2026-02-28 12:13:13 +08:00
Converted NonUniqueSlugException into a problem details exception
This commit is contained in:
@@ -4,10 +4,19 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Exception;
|
||||
|
||||
use Fig\Http\Message\StatusCodeInterface;
|
||||
use Zend\ProblemDetails\Exception\CommonProblemDetailsExceptionTrait;
|
||||
use Zend\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
class NonUniqueSlugException extends InvalidArgumentException
|
||||
class NonUniqueSlugException extends InvalidArgumentException implements ProblemDetailsExceptionInterface
|
||||
{
|
||||
use CommonProblemDetailsExceptionTrait;
|
||||
|
||||
private const TITLE = 'Invalid custom slug';
|
||||
public const TYPE = 'INVALID_SLUG';
|
||||
|
||||
public static function fromSlug(string $slug, ?string $domain): self
|
||||
{
|
||||
$suffix = '';
|
||||
@@ -15,6 +24,13 @@ class NonUniqueSlugException extends InvalidArgumentException
|
||||
$suffix = sprintf(' for domain "%s"', $domain);
|
||||
}
|
||||
|
||||
return new self(sprintf('Provided slug "%s" is not unique%s.', $slug, $suffix));
|
||||
$e = new self(sprintf('Provided slug "%s" is already in use%s.', $slug, $suffix));
|
||||
|
||||
$e->detail = $e->getMessage();
|
||||
$e->title = self::TITLE;
|
||||
$e->type = self::TYPE;
|
||||
$e->status = StatusCodeInterface::STATUS_BAD_REQUEST;
|
||||
|
||||
return $e;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user