mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-09 16:53:11 +08:00
Moved AuthenticationException to Rest module
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
namespace Shlinkio\Shlink\Rest\Action;
|
||||
|
||||
use Acelaya\UrlShortener\Exception\AuthenticationException;
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Shlinkio\Shlink\Rest\Exception\AuthenticationException;
|
||||
use Shlinkio\Shlink\Rest\Service\RestTokenService;
|
||||
use Shlinkio\Shlink\Rest\Service\RestTokenServiceInterface;
|
||||
use Shlinkio\Shlink\Rest\Util\RestUtils;
|
||||
|
||||
12
module/Rest/src/Exception/AuthenticationException.php
Normal file
12
module/Rest/src/Exception/AuthenticationException.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace Shlinkio\Shlink\Rest\Exception;
|
||||
|
||||
use Acelaya\UrlShortener\Exception\ExceptionInterface;
|
||||
|
||||
class AuthenticationException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
public static function fromCredentials($username, $password)
|
||||
{
|
||||
return new self(sprintf('Invalid credentials. Username -> "%s". Password -> "%s"', $username, $password));
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
namespace Shlinkio\Shlink\Rest\Service;
|
||||
|
||||
use Acelaya\UrlShortener\Entity\RestToken;
|
||||
use Acelaya\UrlShortener\Exception\AuthenticationException;
|
||||
use Acelaya\UrlShortener\Exception\InvalidArgumentException;
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Shlinkio\Shlink\Rest\Exception\AuthenticationException;
|
||||
|
||||
class RestTokenService implements RestTokenServiceInterface
|
||||
{
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
namespace Shlinkio\Shlink\Rest\Service;
|
||||
|
||||
use Acelaya\UrlShortener\Entity\RestToken;
|
||||
use Acelaya\UrlShortener\Exception\AuthenticationException;
|
||||
use Acelaya\UrlShortener\Exception\InvalidArgumentException;
|
||||
use Shlinkio\Shlink\Rest\Exception\AuthenticationException;
|
||||
|
||||
interface RestTokenServiceInterface
|
||||
{
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
namespace Shlinkio\Shlink\Rest\Util;
|
||||
|
||||
use Acelaya\UrlShortener\Exception;
|
||||
use Acelaya\UrlShortener\Exception as Core;
|
||||
use Shlinkio\Shlink\Rest\Exception as Rest;
|
||||
|
||||
class RestUtils
|
||||
{
|
||||
@@ -12,16 +13,16 @@ class RestUtils
|
||||
const INVALID_AUTH_TOKEN_ERROR = 'INVALID_AUTH_TOKEN_ERROR';
|
||||
const UNKNOWN_ERROR = 'UNKNOWN_ERROR';
|
||||
|
||||
public static function getRestErrorCodeFromException(Exception\ExceptionInterface $e)
|
||||
public static function getRestErrorCodeFromException(Core\ExceptionInterface $e)
|
||||
{
|
||||
switch (true) {
|
||||
case $e instanceof Exception\InvalidShortCodeException:
|
||||
case $e instanceof Core\InvalidShortCodeException:
|
||||
return self::INVALID_SHORTCODE_ERROR;
|
||||
case $e instanceof Exception\InvalidUrlException:
|
||||
case $e instanceof Core\InvalidUrlException:
|
||||
return self::INVALID_URL_ERROR;
|
||||
case $e instanceof Exception\InvalidArgumentException:
|
||||
case $e instanceof Core\InvalidArgumentException:
|
||||
return self::INVALID_ARGUMENT_ERROR;
|
||||
case $e instanceof Exception\AuthenticationException:
|
||||
case $e instanceof Rest\AuthenticationException:
|
||||
return self::INVALID_CREDENTIALS_ERROR;
|
||||
default:
|
||||
return self::UNKNOWN_ERROR;
|
||||
|
||||
Reference in New Issue
Block a user