Moved InvalidShortCode exception handling to problem details

This commit is contained in:
Alejandro Celaya
2019-11-24 12:41:12 +01:00
parent 09321eaa93
commit 6f0afe269d
12 changed files with 113 additions and 85 deletions

View File

@@ -14,20 +14,17 @@ class InvalidShortCodeException extends RuntimeException implements ProblemDetai
{
use CommonProblemDetailsExceptionTrait;
public const TITLE = 'Invalid short code';
private const TITLE = 'Invalid short code';
public const TYPE = 'INVALID_SHORTCODE';
public static function fromNotFoundShortCode(string $shortCode): self
{
$e = new self(sprintf('No URL found for short code "%s"', $shortCode));
$e->detail = $e->getMessage();
$e->title = self::TITLE;
$e->type = self::TYPE;
$e->status = StatusCodeInterface::STATUS_NOT_FOUND;
$e->additional = [
'error' => $e->type,
'message' => $e->detail,
];
return $e;
}