mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 01:33:11 +08:00
Added logic to properly map all existing errors from v3 to v2 in the API
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user