Ported Exceptions\Api\*. Some small optimization.
This commit is contained in:
parent
8d6197b116
commit
64b042bf77
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Exception\Api;
|
||||
|
||||
class ApiException extends \Exception
|
||||
{
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Exception\Api;
|
||||
|
||||
use src\PointToolsBundle\Exception\Api\ApiException;
|
||||
|
||||
class ForbiddenException extends ApiException
|
||||
{
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Exception\Api;
|
||||
|
||||
use src\PointToolsBundle\Exception\Api\ApiException;
|
||||
|
||||
class InvalidResponseException extends ApiException
|
||||
{
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Exception\Api;
|
||||
|
||||
use src\PointToolsBundle\Exception\Api\ApiException;
|
||||
|
||||
class NetworkException extends ApiException
|
||||
{
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Exception\Api;
|
||||
|
||||
use src\PointToolsBundle\Exception\Api\ApiException;
|
||||
|
||||
class NotFoundException extends ApiException
|
||||
{
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Exception\Api;
|
||||
|
||||
use src\PointToolsBundle\Exception\Api\ApiException;
|
||||
|
||||
class ServerProblemException extends ApiException
|
||||
{
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Exception\Api;
|
||||
|
||||
use src\PointToolsBundle\Exception\Api\ApiException;
|
||||
|
||||
class UnauthorizedException extends ApiException
|
||||
{
|
||||
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Exception\Api;
|
||||
|
||||
use src\PointToolsBundle\Exception\Api\NotFoundException;
|
||||
|
||||
class UserNotFoundException extends NotFoundException
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $userId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $login;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param int $userId
|
||||
*/
|
||||
public function __construct($message = 'User not found', $code = 0, \Exception $previous = null, $userId = null, $login = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
|
||||
$this->userId = $userId;
|
||||
$this->login = $login;
|
||||
}
|
||||
|
||||
public function getUserId(): int
|
||||
{
|
||||
return $this->userId;
|
||||
}
|
||||
|
||||
public function getLogin(): string
|
||||
{
|
||||
return $this->login;
|
||||
}
|
||||
}
|
9
src/Exception/Api/ApiException.php
Normal file
9
src/Exception/Api/ApiException.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Exception\Api;
|
||||
|
||||
class ApiException extends \Exception
|
||||
{
|
||||
|
||||
}
|
15
src/Exception/Api/ForbiddenException.php
Normal file
15
src/Exception/Api/ForbiddenException.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Exception\Api;
|
||||
|
||||
class ForbiddenException extends ApiException
|
||||
{
|
||||
public function __construct(
|
||||
string $message = 'Forbidden',
|
||||
int $code = 403,
|
||||
?\Throwable $previous = null
|
||||
) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
8
src/Exception/Api/InvalidResponseException.php
Normal file
8
src/Exception/Api/InvalidResponseException.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Exception\Api;
|
||||
|
||||
class InvalidResponseException extends ApiException
|
||||
{
|
||||
}
|
9
src/Exception/Api/NetworkException.php
Normal file
9
src/Exception/Api/NetworkException.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Exception\Api;
|
||||
|
||||
class NetworkException extends ApiException
|
||||
{
|
||||
|
||||
}
|
15
src/Exception/Api/NotFoundException.php
Normal file
15
src/Exception/Api/NotFoundException.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Exception\Api;
|
||||
|
||||
class NotFoundException extends ApiException
|
||||
{
|
||||
public function __construct(
|
||||
string $message = 'Resource not found',
|
||||
int $code = 404,
|
||||
?\Throwable $previous = null
|
||||
) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
15
src/Exception/Api/ServerProblemException.php
Normal file
15
src/Exception/Api/ServerProblemException.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Exception\Api;
|
||||
|
||||
class ServerProblemException extends ApiException
|
||||
{
|
||||
public function __construct(
|
||||
string $message = 'Server error',
|
||||
int $code = 500,
|
||||
?\Throwable $previous = null
|
||||
) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
15
src/Exception/Api/UnauthorizedException.php
Normal file
15
src/Exception/Api/UnauthorizedException.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Exception\Api;
|
||||
|
||||
class UnauthorizedException extends ApiException
|
||||
{
|
||||
public function __construct(
|
||||
string $message = 'Unauthorized',
|
||||
int $code = 401,
|
||||
?\Throwable $previous = null
|
||||
) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
27
src/Exception/Api/UserNotFoundException.php
Normal file
27
src/Exception/Api/UserNotFoundException.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Exception\Api;
|
||||
|
||||
class UserNotFoundException extends NotFoundException
|
||||
{
|
||||
public function __construct(
|
||||
$message = 'User not found',
|
||||
$code = 0,
|
||||
\Exception $previous = null,
|
||||
private readonly ?int $userId = null,
|
||||
private readonly ?string $login = null,
|
||||
) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
public function getUserId(): ?int
|
||||
{
|
||||
return $this->userId;
|
||||
}
|
||||
|
||||
public function getLogin(): ?string
|
||||
{
|
||||
return $this->login;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue