12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- declare(strict_types=1);
- namespace Shlinkio\Shlink\Core\Exception;
- use Fig\Http\Message\StatusCodeInterface;
- use Mezzio\ProblemDetails\Exception\CommonProblemDetailsExceptionTrait;
- use Mezzio\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
- use function sprintf;
- class ShortUrlNotFoundException extends DomainException implements ProblemDetailsExceptionInterface
- {
- use CommonProblemDetailsExceptionTrait;
- private const TITLE = 'Short URL not found';
- private const TYPE = 'INVALID_SHORTCODE';
- public static function fromNotFoundShortCode(string $shortCode, ?string $domain = null): self
- {
- $suffix = $domain === null ? '' : sprintf(' for domain "%s"', $domain);
- $e = new self(sprintf('No URL found with short code "%s"%s', $shortCode, $suffix));
- $e->detail = $e->getMessage();
- $e->title = self::TITLE;
- $e->type = self::TYPE;
- $e->status = StatusCodeInterface::STATUS_NOT_FOUND;
- $e->additional = ['shortCode' => $shortCode];
- if ($domain !== null) {
- $e->additional['domain'] = $domain;
- }
- return $e;
- }
- }
|