mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Added logic to properly map all existing errors from v3 to v2 in the API
This commit is contained in:
parent
cd4fe4362b
commit
905f51fbd0
@ -69,7 +69,7 @@
|
|||||||
"phpunit/phpunit": "^9.5",
|
"phpunit/phpunit": "^9.5",
|
||||||
"roave/security-advisories": "dev-master",
|
"roave/security-advisories": "dev-master",
|
||||||
"shlinkio/php-coding-standard": "~2.3.0",
|
"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",
|
"symfony/var-dumper": "^6.1",
|
||||||
"veewee/composer-run-parallel": "^1.1"
|
"veewee/composer-run-parallel": "^1.1"
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,7 @@ class DeleteShortUrlException extends DomainException implements ProblemDetailsE
|
|||||||
use CommonProblemDetailsExceptionTrait;
|
use CommonProblemDetailsExceptionTrait;
|
||||||
|
|
||||||
private const TITLE = 'Cannot delete short URL';
|
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
|
public static function fromVisitsThreshold(int $threshold, ShortUrlIdentifier $identifier): self
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,7 @@ class DomainNotFoundException extends DomainException implements ProblemDetailsE
|
|||||||
use CommonProblemDetailsExceptionTrait;
|
use CommonProblemDetailsExceptionTrait;
|
||||||
|
|
||||||
private const TITLE = 'Domain not found';
|
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)
|
private function __construct(string $message, array $additional)
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,7 @@ class ForbiddenTagOperationException extends DomainException implements ProblemD
|
|||||||
use CommonProblemDetailsExceptionTrait;
|
use CommonProblemDetailsExceptionTrait;
|
||||||
|
|
||||||
private const TITLE = 'Forbidden tag operation';
|
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
|
public static function forDeletion(): self
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@ class InvalidUrlException extends DomainException implements ProblemDetailsExcep
|
|||||||
use CommonProblemDetailsExceptionTrait;
|
use CommonProblemDetailsExceptionTrait;
|
||||||
|
|
||||||
private const TITLE = 'Invalid URL';
|
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
|
public static function fromUrl(string $url, ?Throwable $previous = null): self
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@ class NonUniqueSlugException extends InvalidArgumentException implements Problem
|
|||||||
use CommonProblemDetailsExceptionTrait;
|
use CommonProblemDetailsExceptionTrait;
|
||||||
|
|
||||||
private const TITLE = 'Invalid custom slug';
|
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
|
public static function fromSlug(string $slug, ?string $domain = null): self
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@ class ShortUrlNotFoundException extends DomainException implements ProblemDetail
|
|||||||
use CommonProblemDetailsExceptionTrait;
|
use CommonProblemDetailsExceptionTrait;
|
||||||
|
|
||||||
private const TITLE = 'Short URL not found';
|
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
|
public static function fromNotFound(ShortUrlIdentifier $identifier): self
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@ class TagConflictException extends RuntimeException implements ProblemDetailsExc
|
|||||||
use CommonProblemDetailsExceptionTrait;
|
use CommonProblemDetailsExceptionTrait;
|
||||||
|
|
||||||
private const TITLE = 'Tag conflict';
|
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
|
public static function forExistingTag(TagRenaming $renaming): self
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,7 @@ class TagNotFoundException extends DomainException implements ProblemDetailsExce
|
|||||||
use CommonProblemDetailsExceptionTrait;
|
use CommonProblemDetailsExceptionTrait;
|
||||||
|
|
||||||
private const TITLE = 'Tag not found';
|
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
|
public static function fromTag(string $tag): self
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,7 @@ class DeleteShortUrlExceptionTest extends TestCase
|
|||||||
'threshold' => $threshold,
|
'threshold' => $threshold,
|
||||||
], $e->getAdditionalData());
|
], $e->getAdditionalData());
|
||||||
self::assertEquals('Cannot delete short URL', $e->getTitle());
|
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());
|
self::assertEquals(422, $e->getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ class DomainNotFoundExceptionTest extends TestCase
|
|||||||
self::assertEquals($expectedMessage, $e->getMessage());
|
self::assertEquals($expectedMessage, $e->getMessage());
|
||||||
self::assertEquals($expectedMessage, $e->getDetail());
|
self::assertEquals($expectedMessage, $e->getDetail());
|
||||||
self::assertEquals('Domain not found', $e->getTitle());
|
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(['id' => $id], $e->getAdditionalData());
|
||||||
self::assertEquals(404, $e->getStatus());
|
self::assertEquals(404, $e->getStatus());
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ class DomainNotFoundExceptionTest extends TestCase
|
|||||||
self::assertEquals($expectedMessage, $e->getMessage());
|
self::assertEquals($expectedMessage, $e->getMessage());
|
||||||
self::assertEquals($expectedMessage, $e->getDetail());
|
self::assertEquals($expectedMessage, $e->getDetail());
|
||||||
self::assertEquals('Domain not found', $e->getTitle());
|
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(['authority' => $authority], $e->getAdditionalData());
|
||||||
self::assertEquals(404, $e->getStatus());
|
self::assertEquals(404, $e->getStatus());
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ class ForbiddenTagOperationExceptionTest extends TestCase
|
|||||||
self::assertEquals($expectedMessage, $e->getMessage());
|
self::assertEquals($expectedMessage, $e->getMessage());
|
||||||
self::assertEquals($expectedMessage, $e->getDetail());
|
self::assertEquals($expectedMessage, $e->getDetail());
|
||||||
self::assertEquals('Forbidden tag operation', $e->getTitle());
|
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());
|
self::assertEquals(403, $e->getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class InvalidUrlExceptionTest extends TestCase
|
|||||||
self::assertEquals($expectedMessage, $e->getMessage());
|
self::assertEquals($expectedMessage, $e->getMessage());
|
||||||
self::assertEquals($expectedMessage, $e->getDetail());
|
self::assertEquals($expectedMessage, $e->getDetail());
|
||||||
self::assertEquals('Invalid URL', $e->getTitle());
|
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(['url' => $url], $e->getAdditionalData());
|
||||||
self::assertEquals(StatusCodeInterface::STATUS_BAD_REQUEST, $e->getCode());
|
self::assertEquals(StatusCodeInterface::STATUS_BAD_REQUEST, $e->getCode());
|
||||||
self::assertEquals(StatusCodeInterface::STATUS_BAD_REQUEST, $e->getStatus());
|
self::assertEquals(StatusCodeInterface::STATUS_BAD_REQUEST, $e->getStatus());
|
||||||
|
@ -25,7 +25,7 @@ class NonUniqueSlugExceptionTest extends TestCase
|
|||||||
self::assertEquals($expectedMessage, $e->getMessage());
|
self::assertEquals($expectedMessage, $e->getMessage());
|
||||||
self::assertEquals($expectedMessage, $e->getDetail());
|
self::assertEquals($expectedMessage, $e->getDetail());
|
||||||
self::assertEquals('Invalid custom slug', $e->getTitle());
|
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(400, $e->getStatus());
|
||||||
self::assertEquals($expectedAdditional, $e->getAdditionalData());
|
self::assertEquals($expectedAdditional, $e->getAdditionalData());
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class ShortUrlNotFoundExceptionTest extends TestCase
|
|||||||
self::assertEquals($expectedMessage, $e->getMessage());
|
self::assertEquals($expectedMessage, $e->getMessage());
|
||||||
self::assertEquals($expectedMessage, $e->getDetail());
|
self::assertEquals($expectedMessage, $e->getDetail());
|
||||||
self::assertEquals('Short URL not found', $e->getTitle());
|
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(404, $e->getStatus());
|
||||||
self::assertEquals($expectedAdditional, $e->getAdditionalData());
|
self::assertEquals($expectedAdditional, $e->getAdditionalData());
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class TagConflictExceptionTest extends TestCase
|
|||||||
self::assertEquals($expectedMessage, $e->getMessage());
|
self::assertEquals($expectedMessage, $e->getMessage());
|
||||||
self::assertEquals($expectedMessage, $e->getDetail());
|
self::assertEquals($expectedMessage, $e->getDetail());
|
||||||
self::assertEquals('Tag conflict', $e->getTitle());
|
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(['oldName' => $oldName, 'newName' => $newName], $e->getAdditionalData());
|
||||||
self::assertEquals(409, $e->getStatus());
|
self::assertEquals(409, $e->getStatus());
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ class TagNotFoundExceptionTest extends TestCase
|
|||||||
self::assertEquals($expectedMessage, $e->getMessage());
|
self::assertEquals($expectedMessage, $e->getMessage());
|
||||||
self::assertEquals($expectedMessage, $e->getDetail());
|
self::assertEquals($expectedMessage, $e->getDetail());
|
||||||
self::assertEquals('Tag not found', $e->getTitle());
|
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(['tag' => $tag], $e->getAdditionalData());
|
||||||
self::assertEquals(404, $e->getStatus());
|
self::assertEquals(404, $e->getStatus());
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ use function sprintf;
|
|||||||
|
|
||||||
class ConfigProvider
|
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';
|
private const UNVERSIONED_ROUTES_PREFIX = '/rest';
|
||||||
public const UNVERSIONED_HEALTH_ENDPOINT_NAME = 'unversioned_health';
|
public const UNVERSIONED_HEALTH_ENDPOINT_NAME = 'unversioned_health';
|
||||||
|
|
||||||
|
@ -5,6 +5,14 @@ declare(strict_types=1);
|
|||||||
namespace Shlinkio\Shlink\Rest\Exception;
|
namespace Shlinkio\Shlink\Rest\Exception;
|
||||||
|
|
||||||
use Mezzio\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
|
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;
|
use Shlinkio\Shlink\Core\Exception\ValidationException;
|
||||||
|
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
@ -68,6 +76,17 @@ class BackwardsCompatibleProblemDetailsException extends RuntimeException implem
|
|||||||
{
|
{
|
||||||
return match ($wrappedType) {
|
return match ($wrappedType) {
|
||||||
ValidationException::TYPE => 'INVALID_ARGUMENT',
|
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,
|
default => $wrappedType,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ class MercureException extends RuntimeException implements ProblemDetailsExcepti
|
|||||||
use CommonProblemDetailsExceptionTrait;
|
use CommonProblemDetailsExceptionTrait;
|
||||||
|
|
||||||
private const TITLE = 'Mercure integration not configured';
|
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
|
public static function mercureNotConfigured(): self
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@ class MissingAuthenticationException extends RuntimeException implements Problem
|
|||||||
use CommonProblemDetailsExceptionTrait;
|
use CommonProblemDetailsExceptionTrait;
|
||||||
|
|
||||||
private const TITLE = 'Invalid authorization';
|
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
|
public static function forHeaders(array $expectedHeaders): self
|
||||||
{
|
{
|
||||||
|
@ -12,13 +12,15 @@ class VerifyAuthenticationException extends RuntimeException implements ProblemD
|
|||||||
{
|
{
|
||||||
use CommonProblemDetailsExceptionTrait;
|
use CommonProblemDetailsExceptionTrait;
|
||||||
|
|
||||||
|
public const TYPE = 'https://shlink.io/api/error/invalid-api-key';
|
||||||
|
|
||||||
public static function forInvalidApiKey(): self
|
public static function forInvalidApiKey(): self
|
||||||
{
|
{
|
||||||
$e = new self('Provided API key does not exist or is invalid.');
|
$e = new self('Provided API key does not exist or is invalid.');
|
||||||
|
|
||||||
$e->detail = $e->getMessage();
|
$e->detail = $e->getMessage();
|
||||||
$e->title = 'Invalid API key';
|
$e->title = 'Invalid API key';
|
||||||
$e->type = 'INVALID_API_KEY';
|
$e->type = self::TYPE;
|
||||||
$e->status = StatusCodeInterface::STATUS_UNAUTHORIZED;
|
$e->status = StatusCodeInterface::STATUS_UNAUTHORIZED;
|
||||||
|
|
||||||
return $e;
|
return $e;
|
||||||
|
@ -48,10 +48,10 @@ class ConfigProviderTest extends TestCase
|
|||||||
['path' => '/health'],
|
['path' => '/health'],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
['path' => '/rest/v{version:1|2}/foo'],
|
['path' => '/rest/v{version:1|2|3}/foo'],
|
||||||
['path' => '/rest/v{version:1|2}/bar'],
|
['path' => '/rest/v{version:1|2|3}/bar'],
|
||||||
['path' => '/rest/v{version:1|2}/baz/foo'],
|
['path' => '/rest/v{version:1|2|3}/baz/foo'],
|
||||||
['path' => '/rest/v{version:1|2}/health'],
|
['path' => '/rest/v{version:1|2|3}/health'],
|
||||||
['path' => '/rest/health', 'name' => ConfigProvider::UNVERSIONED_HEALTH_ENDPOINT_NAME],
|
['path' => '/rest/health', 'name' => ConfigProvider::UNVERSIONED_HEALTH_ENDPOINT_NAME],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@ -62,9 +62,9 @@ class ConfigProviderTest extends TestCase
|
|||||||
['path' => '/baz/foo'],
|
['path' => '/baz/foo'],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
['path' => '/rest/v{version:1|2}/foo'],
|
['path' => '/rest/v{version:1|2|3}/foo'],
|
||||||
['path' => '/rest/v{version:1|2}/bar'],
|
['path' => '/rest/v{version:1|2|3}/bar'],
|
||||||
['path' => '/rest/v{version:1|2}/baz/foo'],
|
['path' => '/rest/v{version:1|2|3}/baz/foo'],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ class MissingAuthenticationExceptionTest extends TestCase
|
|||||||
private function assertCommonExceptionShape(MissingAuthenticationException $e): void
|
private function assertCommonExceptionShape(MissingAuthenticationException $e): void
|
||||||
{
|
{
|
||||||
self::assertEquals('Invalid authorization', $e->getTitle());
|
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());
|
self::assertEquals(401, $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user