diff --git a/composer.json b/composer.json index ad11461b..168418a5 100644 --- a/composer.json +++ b/composer.json @@ -69,7 +69,7 @@ "phpunit/phpunit": "^9.5", "roave/security-advisories": "dev-master", "shlinkio/php-coding-standard": "~2.3.0", - "shlinkio/shlink-test-utils": "^3.1.0", + "shlinkio/shlink-test-utils": "^3.2", "symfony/var-dumper": "^6.1", "veewee/composer-run-parallel": "^1.1" }, diff --git a/module/Core/src/Exception/DeleteShortUrlException.php b/module/Core/src/Exception/DeleteShortUrlException.php index 0d331400..f6638221 100644 --- a/module/Core/src/Exception/DeleteShortUrlException.php +++ b/module/Core/src/Exception/DeleteShortUrlException.php @@ -16,7 +16,7 @@ class DeleteShortUrlException extends DomainException implements ProblemDetailsE use CommonProblemDetailsExceptionTrait; private const TITLE = 'Cannot delete short URL'; - private const TYPE = 'INVALID_SHORT_URL_DELETION'; + public const TYPE = 'https://shlink.io/api/error/invalid-short-url-deletion'; public static function fromVisitsThreshold(int $threshold, ShortUrlIdentifier $identifier): self { diff --git a/module/Core/src/Exception/DomainNotFoundException.php b/module/Core/src/Exception/DomainNotFoundException.php index cb19608a..aca67813 100644 --- a/module/Core/src/Exception/DomainNotFoundException.php +++ b/module/Core/src/Exception/DomainNotFoundException.php @@ -15,7 +15,7 @@ class DomainNotFoundException extends DomainException implements ProblemDetailsE use CommonProblemDetailsExceptionTrait; private const TITLE = 'Domain not found'; - private const TYPE = 'DOMAIN_NOT_FOUND'; + public const TYPE = 'https://shlink.io/api/error/domain-not-found'; private function __construct(string $message, array $additional) { diff --git a/module/Core/src/Exception/ForbiddenTagOperationException.php b/module/Core/src/Exception/ForbiddenTagOperationException.php index d4200c92..6da1cb61 100644 --- a/module/Core/src/Exception/ForbiddenTagOperationException.php +++ b/module/Core/src/Exception/ForbiddenTagOperationException.php @@ -13,7 +13,7 @@ class ForbiddenTagOperationException extends DomainException implements ProblemD use CommonProblemDetailsExceptionTrait; private const TITLE = 'Forbidden tag operation'; - private const TYPE = 'FORBIDDEN_OPERATION'; + public const TYPE = 'https://shlink.io/api/error/forbidden-tag-operation'; public static function forDeletion(): self { diff --git a/module/Core/src/Exception/InvalidUrlException.php b/module/Core/src/Exception/InvalidUrlException.php index ee4caaf6..6d1f93c6 100644 --- a/module/Core/src/Exception/InvalidUrlException.php +++ b/module/Core/src/Exception/InvalidUrlException.php @@ -16,7 +16,7 @@ class InvalidUrlException extends DomainException implements ProblemDetailsExcep use CommonProblemDetailsExceptionTrait; private const TITLE = 'Invalid URL'; - private const TYPE = 'INVALID_URL'; + public const TYPE = 'https://shlink.io/api/error/invalid-url'; public static function fromUrl(string $url, ?Throwable $previous = null): self { diff --git a/module/Core/src/Exception/NonUniqueSlugException.php b/module/Core/src/Exception/NonUniqueSlugException.php index f61c480f..dc1fcca9 100644 --- a/module/Core/src/Exception/NonUniqueSlugException.php +++ b/module/Core/src/Exception/NonUniqueSlugException.php @@ -16,7 +16,7 @@ class NonUniqueSlugException extends InvalidArgumentException implements Problem use CommonProblemDetailsExceptionTrait; private const TITLE = 'Invalid custom slug'; - private const TYPE = 'INVALID_SLUG'; + public const TYPE = 'https://shlink.io/api/error/non-unique-slug'; public static function fromSlug(string $slug, ?string $domain = null): self { diff --git a/module/Core/src/Exception/ShortUrlNotFoundException.php b/module/Core/src/Exception/ShortUrlNotFoundException.php index c59c20ef..4da6972e 100644 --- a/module/Core/src/Exception/ShortUrlNotFoundException.php +++ b/module/Core/src/Exception/ShortUrlNotFoundException.php @@ -16,7 +16,7 @@ class ShortUrlNotFoundException extends DomainException implements ProblemDetail use CommonProblemDetailsExceptionTrait; private const TITLE = 'Short URL not found'; - private const TYPE = 'INVALID_SHORTCODE'; + public const TYPE = 'https://shlink.io/api/error/short-url-not-found'; public static function fromNotFound(ShortUrlIdentifier $identifier): self { diff --git a/module/Core/src/Exception/TagConflictException.php b/module/Core/src/Exception/TagConflictException.php index d551ec19..09ea7be4 100644 --- a/module/Core/src/Exception/TagConflictException.php +++ b/module/Core/src/Exception/TagConflictException.php @@ -16,7 +16,7 @@ class TagConflictException extends RuntimeException implements ProblemDetailsExc use CommonProblemDetailsExceptionTrait; private const TITLE = 'Tag conflict'; - private const TYPE = 'TAG_CONFLICT'; + public const TYPE = 'https://shlink.io/api/error/tag-conflict'; public static function forExistingTag(TagRenaming $renaming): self { diff --git a/module/Core/src/Exception/TagNotFoundException.php b/module/Core/src/Exception/TagNotFoundException.php index 18c1554c..da2426aa 100644 --- a/module/Core/src/Exception/TagNotFoundException.php +++ b/module/Core/src/Exception/TagNotFoundException.php @@ -15,7 +15,7 @@ class TagNotFoundException extends DomainException implements ProblemDetailsExce use CommonProblemDetailsExceptionTrait; private const TITLE = 'Tag not found'; - private const TYPE = 'TAG_NOT_FOUND'; + public const TYPE = 'https://shlink.io/api/error/tag-not-found'; public static function fromTag(string $tag): self { diff --git a/module/Core/test/Exception/DeleteShortUrlExceptionTest.php b/module/Core/test/Exception/DeleteShortUrlExceptionTest.php index b331bdc2..e658e55d 100644 --- a/module/Core/test/Exception/DeleteShortUrlExceptionTest.php +++ b/module/Core/test/Exception/DeleteShortUrlExceptionTest.php @@ -37,7 +37,7 @@ class DeleteShortUrlExceptionTest extends TestCase 'threshold' => $threshold, ], $e->getAdditionalData()); self::assertEquals('Cannot delete short URL', $e->getTitle()); - self::assertEquals('INVALID_SHORT_URL_DELETION', $e->getType()); + self::assertEquals('https://shlink.io/api/error/invalid-short-url-deletion', $e->getType()); self::assertEquals(422, $e->getStatus()); } diff --git a/module/Core/test/Exception/DomainNotFoundExceptionTest.php b/module/Core/test/Exception/DomainNotFoundExceptionTest.php index 5f2b9889..f2f5daba 100644 --- a/module/Core/test/Exception/DomainNotFoundExceptionTest.php +++ b/module/Core/test/Exception/DomainNotFoundExceptionTest.php @@ -21,7 +21,7 @@ class DomainNotFoundExceptionTest extends TestCase self::assertEquals($expectedMessage, $e->getMessage()); self::assertEquals($expectedMessage, $e->getDetail()); self::assertEquals('Domain not found', $e->getTitle()); - self::assertEquals('DOMAIN_NOT_FOUND', $e->getType()); + self::assertEquals('https://shlink.io/api/error/domain-not-found', $e->getType()); self::assertEquals(['id' => $id], $e->getAdditionalData()); self::assertEquals(404, $e->getStatus()); } @@ -36,7 +36,7 @@ class DomainNotFoundExceptionTest extends TestCase self::assertEquals($expectedMessage, $e->getMessage()); self::assertEquals($expectedMessage, $e->getDetail()); self::assertEquals('Domain not found', $e->getTitle()); - self::assertEquals('DOMAIN_NOT_FOUND', $e->getType()); + self::assertEquals('https://shlink.io/api/error/domain-not-found', $e->getType()); self::assertEquals(['authority' => $authority], $e->getAdditionalData()); self::assertEquals(404, $e->getStatus()); } diff --git a/module/Core/test/Exception/ForbiddenTagOperationExceptionTest.php b/module/Core/test/Exception/ForbiddenTagOperationExceptionTest.php index 40ccd0ee..b064cf91 100644 --- a/module/Core/test/Exception/ForbiddenTagOperationExceptionTest.php +++ b/module/Core/test/Exception/ForbiddenTagOperationExceptionTest.php @@ -25,7 +25,7 @@ class ForbiddenTagOperationExceptionTest extends TestCase self::assertEquals($expectedMessage, $e->getMessage()); self::assertEquals($expectedMessage, $e->getDetail()); self::assertEquals('Forbidden tag operation', $e->getTitle()); - self::assertEquals('FORBIDDEN_OPERATION', $e->getType()); + self::assertEquals('https://shlink.io/api/error/forbidden-tag-operation', $e->getType()); self::assertEquals(403, $e->getStatus()); } diff --git a/module/Core/test/Exception/InvalidUrlExceptionTest.php b/module/Core/test/Exception/InvalidUrlExceptionTest.php index 5351c1b3..e9b0d75a 100644 --- a/module/Core/test/Exception/InvalidUrlExceptionTest.php +++ b/module/Core/test/Exception/InvalidUrlExceptionTest.php @@ -27,7 +27,7 @@ class InvalidUrlExceptionTest extends TestCase self::assertEquals($expectedMessage, $e->getMessage()); self::assertEquals($expectedMessage, $e->getDetail()); self::assertEquals('Invalid URL', $e->getTitle()); - self::assertEquals('INVALID_URL', $e->getType()); + self::assertEquals('https://shlink.io/api/error/invalid-url', $e->getType()); self::assertEquals(['url' => $url], $e->getAdditionalData()); self::assertEquals(StatusCodeInterface::STATUS_BAD_REQUEST, $e->getCode()); self::assertEquals(StatusCodeInterface::STATUS_BAD_REQUEST, $e->getStatus()); diff --git a/module/Core/test/Exception/NonUniqueSlugExceptionTest.php b/module/Core/test/Exception/NonUniqueSlugExceptionTest.php index 6720f0f3..77a71df3 100644 --- a/module/Core/test/Exception/NonUniqueSlugExceptionTest.php +++ b/module/Core/test/Exception/NonUniqueSlugExceptionTest.php @@ -25,7 +25,7 @@ class NonUniqueSlugExceptionTest extends TestCase self::assertEquals($expectedMessage, $e->getMessage()); self::assertEquals($expectedMessage, $e->getDetail()); self::assertEquals('Invalid custom slug', $e->getTitle()); - self::assertEquals('INVALID_SLUG', $e->getType()); + self::assertEquals('https://shlink.io/api/error/non-unique-slug', $e->getType()); self::assertEquals(400, $e->getStatus()); self::assertEquals($expectedAdditional, $e->getAdditionalData()); } diff --git a/module/Core/test/Exception/ShortUrlNotFoundExceptionTest.php b/module/Core/test/Exception/ShortUrlNotFoundExceptionTest.php index e86a63cb..2818f350 100644 --- a/module/Core/test/Exception/ShortUrlNotFoundExceptionTest.php +++ b/module/Core/test/Exception/ShortUrlNotFoundExceptionTest.php @@ -29,7 +29,7 @@ class ShortUrlNotFoundExceptionTest extends TestCase self::assertEquals($expectedMessage, $e->getMessage()); self::assertEquals($expectedMessage, $e->getDetail()); self::assertEquals('Short URL not found', $e->getTitle()); - self::assertEquals('INVALID_SHORTCODE', $e->getType()); + self::assertEquals('https://shlink.io/api/error/short-url-not-found', $e->getType()); self::assertEquals(404, $e->getStatus()); self::assertEquals($expectedAdditional, $e->getAdditionalData()); } diff --git a/module/Core/test/Exception/TagConflictExceptionTest.php b/module/Core/test/Exception/TagConflictExceptionTest.php index 4427eb40..ba7dfa1d 100644 --- a/module/Core/test/Exception/TagConflictExceptionTest.php +++ b/module/Core/test/Exception/TagConflictExceptionTest.php @@ -23,7 +23,7 @@ class TagConflictExceptionTest extends TestCase self::assertEquals($expectedMessage, $e->getMessage()); self::assertEquals($expectedMessage, $e->getDetail()); self::assertEquals('Tag conflict', $e->getTitle()); - self::assertEquals('TAG_CONFLICT', $e->getType()); + self::assertEquals('https://shlink.io/api/error/tag-conflict', $e->getType()); self::assertEquals(['oldName' => $oldName, 'newName' => $newName], $e->getAdditionalData()); self::assertEquals(409, $e->getStatus()); } diff --git a/module/Core/test/Exception/TagNotFoundExceptionTest.php b/module/Core/test/Exception/TagNotFoundExceptionTest.php index ccd63788..f22463c2 100644 --- a/module/Core/test/Exception/TagNotFoundExceptionTest.php +++ b/module/Core/test/Exception/TagNotFoundExceptionTest.php @@ -21,7 +21,7 @@ class TagNotFoundExceptionTest extends TestCase self::assertEquals($expectedMessage, $e->getMessage()); self::assertEquals($expectedMessage, $e->getDetail()); self::assertEquals('Tag not found', $e->getTitle()); - self::assertEquals('TAG_NOT_FOUND', $e->getType()); + self::assertEquals('https://shlink.io/api/error/tag-not-found', $e->getType()); self::assertEquals(['tag' => $tag], $e->getAdditionalData()); self::assertEquals(404, $e->getStatus()); } diff --git a/module/Rest/src/ConfigProvider.php b/module/Rest/src/ConfigProvider.php index 6d389038..215a4d6e 100644 --- a/module/Rest/src/ConfigProvider.php +++ b/module/Rest/src/ConfigProvider.php @@ -11,7 +11,7 @@ use function sprintf; class ConfigProvider { - private const ROUTES_PREFIX = '/rest/v{version:1|2}'; + private const ROUTES_PREFIX = '/rest/v{version:1|2|3}'; private const UNVERSIONED_ROUTES_PREFIX = '/rest'; public const UNVERSIONED_HEALTH_ENDPOINT_NAME = 'unversioned_health'; diff --git a/module/Rest/src/Exception/BackwardsCompatibleProblemDetailsException.php b/module/Rest/src/Exception/BackwardsCompatibleProblemDetailsException.php index ddc3768f..14a6e934 100644 --- a/module/Rest/src/Exception/BackwardsCompatibleProblemDetailsException.php +++ b/module/Rest/src/Exception/BackwardsCompatibleProblemDetailsException.php @@ -5,6 +5,14 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Rest\Exception; use Mezzio\ProblemDetails\Exception\ProblemDetailsExceptionInterface; +use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException; +use Shlinkio\Shlink\Core\Exception\DomainNotFoundException; +use Shlinkio\Shlink\Core\Exception\ForbiddenTagOperationException; +use Shlinkio\Shlink\Core\Exception\InvalidUrlException; +use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException; +use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; +use Shlinkio\Shlink\Core\Exception\TagConflictException; +use Shlinkio\Shlink\Core\Exception\TagNotFoundException; use Shlinkio\Shlink\Core\Exception\ValidationException; /** @deprecated */ @@ -68,6 +76,17 @@ class BackwardsCompatibleProblemDetailsException extends RuntimeException implem { return match ($wrappedType) { ValidationException::TYPE => 'INVALID_ARGUMENT', + DeleteShortUrlException::TYPE => 'INVALID_SHORT_URL_DELETION', + DomainNotFoundException::TYPE => 'DOMAIN_NOT_FOUND', + ForbiddenTagOperationException::TYPE => 'FORBIDDEN_OPERATION', + InvalidUrlException::TYPE => 'INVALID_URL', + NonUniqueSlugException::TYPE => 'INVALID_SLUG', + ShortUrlNotFoundException::TYPE => 'INVALID_SHORTCODE', + TagConflictException::TYPE => 'TAG_CONFLICT', + TagNotFoundException::TYPE => 'TAG_NOT_FOUND', + MercureException::TYPE => 'MERCURE_NOT_CONFIGURED', + MissingAuthenticationException::TYPE => 'INVALID_AUTHORIZATION', + VerifyAuthenticationException::TYPE => 'INVALID_API_KEY', default => $wrappedType, }; } diff --git a/module/Rest/src/Exception/MercureException.php b/module/Rest/src/Exception/MercureException.php index 9435cb54..0e9a6edb 100644 --- a/module/Rest/src/Exception/MercureException.php +++ b/module/Rest/src/Exception/MercureException.php @@ -13,7 +13,7 @@ class MercureException extends RuntimeException implements ProblemDetailsExcepti use CommonProblemDetailsExceptionTrait; private const TITLE = 'Mercure integration not configured'; - private const TYPE = 'MERCURE_NOT_CONFIGURED'; + public const TYPE = 'https://shlink.io/api/error/mercure-not-configured'; public static function mercureNotConfigured(): self { diff --git a/module/Rest/src/Exception/MissingAuthenticationException.php b/module/Rest/src/Exception/MissingAuthenticationException.php index 99dbc0df..3c1f5b9f 100644 --- a/module/Rest/src/Exception/MissingAuthenticationException.php +++ b/module/Rest/src/Exception/MissingAuthenticationException.php @@ -16,7 +16,7 @@ class MissingAuthenticationException extends RuntimeException implements Problem use CommonProblemDetailsExceptionTrait; private const TITLE = 'Invalid authorization'; - private const TYPE = 'INVALID_AUTHORIZATION'; + public const TYPE = 'https://shlink.io/api/error/missing-authentication'; public static function forHeaders(array $expectedHeaders): self { diff --git a/module/Rest/src/Exception/VerifyAuthenticationException.php b/module/Rest/src/Exception/VerifyAuthenticationException.php index 702230ff..25541d03 100644 --- a/module/Rest/src/Exception/VerifyAuthenticationException.php +++ b/module/Rest/src/Exception/VerifyAuthenticationException.php @@ -12,13 +12,15 @@ class VerifyAuthenticationException extends RuntimeException implements ProblemD { use CommonProblemDetailsExceptionTrait; + public const TYPE = 'https://shlink.io/api/error/invalid-api-key'; + public static function forInvalidApiKey(): self { $e = new self('Provided API key does not exist or is invalid.'); $e->detail = $e->getMessage(); $e->title = 'Invalid API key'; - $e->type = 'INVALID_API_KEY'; + $e->type = self::TYPE; $e->status = StatusCodeInterface::STATUS_UNAUTHORIZED; return $e; diff --git a/module/Rest/test/ConfigProviderTest.php b/module/Rest/test/ConfigProviderTest.php index a3f7d0c9..d3288151 100644 --- a/module/Rest/test/ConfigProviderTest.php +++ b/module/Rest/test/ConfigProviderTest.php @@ -48,10 +48,10 @@ class ConfigProviderTest extends TestCase ['path' => '/health'], ], [ - ['path' => '/rest/v{version:1|2}/foo'], - ['path' => '/rest/v{version:1|2}/bar'], - ['path' => '/rest/v{version:1|2}/baz/foo'], - ['path' => '/rest/v{version:1|2}/health'], + ['path' => '/rest/v{version:1|2|3}/foo'], + ['path' => '/rest/v{version:1|2|3}/bar'], + ['path' => '/rest/v{version:1|2|3}/baz/foo'], + ['path' => '/rest/v{version:1|2|3}/health'], ['path' => '/rest/health', 'name' => ConfigProvider::UNVERSIONED_HEALTH_ENDPOINT_NAME], ], ]; @@ -62,9 +62,9 @@ class ConfigProviderTest extends TestCase ['path' => '/baz/foo'], ], [ - ['path' => '/rest/v{version:1|2}/foo'], - ['path' => '/rest/v{version:1|2}/bar'], - ['path' => '/rest/v{version:1|2}/baz/foo'], + ['path' => '/rest/v{version:1|2|3}/foo'], + ['path' => '/rest/v{version:1|2|3}/bar'], + ['path' => '/rest/v{version:1|2|3}/baz/foo'], ], ]; } diff --git a/module/Rest/test/Exception/MissingAuthenticationExceptionTest.php b/module/Rest/test/Exception/MissingAuthenticationExceptionTest.php index 5d80ca17..ab79ba2f 100644 --- a/module/Rest/test/Exception/MissingAuthenticationExceptionTest.php +++ b/module/Rest/test/Exception/MissingAuthenticationExceptionTest.php @@ -65,7 +65,7 @@ class MissingAuthenticationExceptionTest extends TestCase private function assertCommonExceptionShape(MissingAuthenticationException $e): void { self::assertEquals('Invalid authorization', $e->getTitle()); - self::assertEquals('INVALID_AUTHORIZATION', $e->getType()); + self::assertEquals('https://shlink.io/api/error/missing-authentication', $e->getType()); self::assertEquals(401, $e->getStatus()); } }