Added logic to properly map all existing errors from v3 to v2 in the API

This commit is contained in:
Alejandro Celaya
2022-08-13 17:15:04 +02:00
parent cd4fe4362b
commit 905f51fbd0
24 changed files with 51 additions and 30 deletions

View File

@@ -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
{

View File

@@ -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)
{

View File

@@ -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
{

View File

@@ -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
{

View File

@@ -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
{

View File

@@ -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
{

View File

@@ -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
{

View File

@@ -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
{

View File

@@ -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());
}

View File

@@ -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());
}

View File

@@ -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());
}

View File

@@ -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());

View File

@@ -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());
}

View File

@@ -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());
}

View File

@@ -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());
}

View File

@@ -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());
}