2016-04-17 12:29:23 +03:00
|
|
|
<?php
|
2019-10-05 18:26:10 +03:00
|
|
|
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-07-19 19:01:39 +03:00
|
|
|
namespace Shlinkio\Shlink\Core\Exception;
|
2016-04-17 12:29:23 +03:00
|
|
|
|
2019-11-25 01:24:53 +03:00
|
|
|
use Fig\Http\Message\StatusCodeInterface;
|
2020-01-01 23:11:53 +03:00
|
|
|
use Mezzio\ProblemDetails\Exception\CommonProblemDetailsExceptionTrait;
|
|
|
|
use Mezzio\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
|
2018-10-28 10:24:06 +03:00
|
|
|
use Throwable;
|
2019-02-27 00:56:43 +03:00
|
|
|
|
2018-10-28 10:34:02 +03:00
|
|
|
use function sprintf;
|
2018-10-28 10:24:06 +03:00
|
|
|
|
2019-11-25 01:24:53 +03:00
|
|
|
class InvalidUrlException extends DomainException implements ProblemDetailsExceptionInterface
|
2016-04-17 12:29:23 +03:00
|
|
|
{
|
2019-11-25 01:24:53 +03:00
|
|
|
use CommonProblemDetailsExceptionTrait;
|
|
|
|
|
|
|
|
private const TITLE = 'Invalid URL';
|
2019-11-27 00:12:52 +03:00
|
|
|
private const TYPE = 'INVALID_URL';
|
2019-11-25 01:24:53 +03:00
|
|
|
|
2019-08-01 20:49:54 +03:00
|
|
|
public static function fromUrl(string $url, ?Throwable $previous = null): self
|
2016-04-17 12:29:23 +03:00
|
|
|
{
|
2019-11-25 01:24:53 +03:00
|
|
|
$status = StatusCodeInterface::STATUS_BAD_REQUEST;
|
|
|
|
$e = new self(sprintf('Provided URL %s is invalid. Try with a different one.', $url), $status, $previous);
|
|
|
|
|
|
|
|
$e->detail = $e->getMessage();
|
|
|
|
$e->title = self::TITLE;
|
|
|
|
$e->type = self::TYPE;
|
|
|
|
$e->status = $status;
|
2019-11-27 22:18:36 +03:00
|
|
|
$e->additional = ['url' => $url];
|
2019-11-25 01:24:53 +03:00
|
|
|
|
|
|
|
return $e;
|
2016-04-17 12:29:23 +03:00
|
|
|
}
|
|
|
|
}
|