Files
shlink/module/Core/src/Exception/ShortUrlNotFoundException.php

38 lines
1.1 KiB
PHP
Raw Normal View History

2016-04-17 13:42:52 +02:00
<?php
2019-10-05 17:26:10 +02:00
2017-10-12 10:13:20 +02:00
declare(strict_types=1);
2016-07-19 18:01:39 +02:00
namespace Shlinkio\Shlink\Core\Exception;
2016-04-17 13:42:52 +02:00
use Fig\Http\Message\StatusCodeInterface;
2020-01-01 21:11:53 +01:00
use Mezzio\ProblemDetails\Exception\CommonProblemDetailsExceptionTrait;
use Mezzio\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
use function sprintf;
class ShortUrlNotFoundException extends DomainException implements ProblemDetailsExceptionInterface
2016-04-17 13:42:52 +02:00
{
use CommonProblemDetailsExceptionTrait;
private const TITLE = 'Short URL not found';
2019-11-26 22:12:52 +01:00
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;
}
2016-04-17 13:42:52 +02:00
}