Skip to content

Commit

Permalink
fix exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
daycry committed Nov 23, 2023
1 parent 3795f7d commit b9c0281
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 48 deletions.
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "daycry/restful",
"description": "Rest Server for Codeigniter 4",
"homepage": "https://github.com/daycry/restfull",
"homepage": "https://github.com/daycry/restful",
"authors":
[
{
Expand All @@ -19,7 +19,8 @@
"daycry/jwt": "^1.0",
"daycry/class-finder": "^2.0",
"daycry/cronjob": "^2.0",
"daycry/settings": "^1"
"daycry/settings": "^1",
"daycry/exceptions": "*"
},
"require-dev":
{
Expand Down Expand Up @@ -79,6 +80,9 @@
]
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
Expand Down
4 changes: 2 additions & 2 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Daycry\RestFul;

use Daycry\Exceptions\Interfaces\BaseExceptionInterface;
use Daycry\RestFul\Libraries\Authentication;
use Daycry\RestFul\Exceptions\AuthenticationException;
use Daycry\RestFul\Interfaces\AuthenticatorInterface;
use Daycry\RestFul\Entities\User;
use Daycry\RestFul\Models\UserModel;
use Daycry\RestFul\Interfaces\BaseException;

/**
* @method Result attempt(array $credentials)
Expand Down Expand Up @@ -144,7 +144,7 @@ public function __call(string $method, array $args)
if ($authenticate && method_exists($authenticate, $method)) {
return $authenticate->{$method}(...$args);
}
} catch(BaseException $ex) {
} catch(BaseExceptionInterface $ex) {
return false;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Authenticators/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Daycry\RestFul\Exceptions\AuthenticationException;
use Daycry\RestFul\Models\UserModel;
use Daycry\RestFul\Models\UserIdentityModel;
use CodeIgniter\Config\Services;
use Daycry\RestFul\Entities\User;

class AccessToken extends Base implements AuthenticatorInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/AuthenticationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Daycry\RestFul\Exceptions;

use Daycry\RestFul\Exceptions\RuntimeException;
use Daycry\Exceptions\Exceptions\RuntimeException;

class AuthenticationException extends RuntimeException
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/AuthorizationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Daycry\RestFul\Exceptions;

use Daycry\RestFul\Exceptions\RuntimeException;
use Daycry\Exceptions\Exceptions\RuntimeException;

class AuthorizationException extends RuntimeException
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/CorsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Daycry\RestFul\Exceptions;

use Daycry\RestFul\Exceptions\RuntimeException;
use Daycry\Exceptions\Exceptions\RuntimeException;

class CorsException extends RuntimeException
{
Expand Down
2 changes: 2 additions & 0 deletions src/Exceptions/DatabaseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Daycry\RestFul\Exceptions;

use Daycry\Exceptions\Exceptions\RuntimeException;

class DatabaseException extends RuntimeException
{
}
2 changes: 1 addition & 1 deletion src/Exceptions/FailTooManyRequestsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Daycry\RestFul\Exceptions;

use Daycry\RestFul\Exceptions\RuntimeException;
use Daycry\Exceptions\Exceptions\RuntimeException;

class FailTooManyRequestsException extends RuntimeException
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/ForbiddenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Daycry\RestFul\Exceptions;

use Daycry\RestFul\Exceptions\RuntimeException;
use Daycry\Exceptions\Exceptions\RuntimeException;
use Config\Services;

class ForbiddenException extends RuntimeException
Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/LogicException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Daycry\RestFul\Exceptions;

use Daycry\RestFul\Interfaces\BaseException;
use Daycry\Exceptions\Interfaces\BaseExceptionInterface;

class LogicException extends \LogicException implements BaseException
class LogicException extends \LogicException implements BaseExceptionInterface
{
}
11 changes: 0 additions & 11 deletions src/Exceptions/RuntimeException.php

This file was deleted.

2 changes: 2 additions & 0 deletions src/Exceptions/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Daycry\RestFul\Exceptions;

use Daycry\Exceptions\Exceptions\RuntimeException;

class ValidationException extends RuntimeException
{
public static $authorized = true;
Expand Down
4 changes: 2 additions & 2 deletions src/Filters/AccessFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Config\Services;
use Daycry\Exceptions\Interfaces\BaseExceptionInterface;
use Daycry\RestFul\Exceptions\AuthorizationException;
use Daycry\RestFul\Interfaces\BaseException;
use Daycry\RestFul\Traits\Authenticable;

/**
Expand Down Expand Up @@ -48,7 +48,7 @@ public function before(RequestInterface $request, $arguments = null)
throw AuthorizationException::forNotEnoughPrivilege();
}

} catch(BaseException $ex) {
} catch(BaseExceptionInterface $ex) {

$logger->setAuthorized(false)
->setResponseCode($ex->getCode())
Expand Down
14 changes: 0 additions & 14 deletions src/Interfaces/BaseException.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Libraries/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use Daycry\Encryption\Encryption;
use Daycry\RestFul\Entities\Endpoint;
use CodeIgniter\Debug\Timer;
use Daycry\Exceptions\Interfaces\BaseExceptionInterface;
use Daycry\RestFul\Models\LogModel;
use Daycry\RestFul\Interfaces\BaseException;

class Logger
{
Expand Down Expand Up @@ -85,7 +85,7 @@ public function save(): int
//If authenticator not exists
try {
$userId = auth()->id();
} catch(BaseException $ex) {
} catch(BaseExceptionInterface $ex) {
$userId = null;
}

Expand Down
6 changes: 3 additions & 3 deletions src/RestFul.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
use Daycry\RestFul\Validators\Whitelist;
use Daycry\RestFul\Validators\Limit;
use Daycry\RestFul\Libraries\Logger;
use Daycry\RestFul\Interfaces\BaseException;
use Daycry\RestFul\Exceptions\ForbiddenException;
use Daycry\RestFul\Models\AttemptModel;
use Config\Mimes;
use Daycry\Exceptions\Interfaces\BaseExceptionInterface;
use ReflectionProperty;
use stdClass;

Expand Down Expand Up @@ -152,7 +152,7 @@ public function __destruct()
* @param string $method
* @param array $params The params passed to the controller method
*
* @throws BaseException
* @throws BaseExceptionInterface
*/
public function _remap($method, ...$params)
{
Expand Down Expand Up @@ -199,7 +199,7 @@ public function _remap($method, ...$params)

return call_user_func_array([ $this, $method ], $params);

} catch (BaseException $ex) {
} catch (BaseExceptionInterface $ex) {

if(property_exists($ex, 'authorized')) {
$this->_isRequestAuthorized = (new ReflectionProperty($ex, 'authorized'))->getValue();
Expand Down
6 changes: 3 additions & 3 deletions src/Traits/Authenticable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Daycry\RestFul\Entities\Endpoint;
use Daycry\RestFul\Exceptions\AuthenticationException;
use Daycry\RestFul\Validators\AccessToken;
use Daycry\RestFul\Interfaces\BaseException;
use Daycry\Exceptions\Interfaces\BaseExceptionInterface;

trait Authenticable
{
Expand All @@ -34,7 +34,7 @@ public function doLogin(?Endpoint $endpoint = null)
}
}

} catch(BaseException $ex) {
} catch(BaseExceptionInterface $ex) {
if($strictApiAndAuth || !$alias) {
throw $ex;
}
Expand All @@ -46,7 +46,7 @@ public function doLogin(?Endpoint $endpoint = null)
$authenticator->authenticate();
}

} catch(BaseException $ex) {
} catch(BaseExceptionInterface $ex) {
if($strictApiAndAuth || (!$strictApiAndAuth && !$user)) {
throw $ex;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Validators/Limit.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Daycry\RestFul\Models\LimitModel;
use CodeIgniter\I18n\Time;
use Daycry\RestFul\Exceptions\FailTooManyRequestsException;
use Daycry\RestFul\Interfaces\BaseException;
use Daycry\Exceptions\Interfaces\BaseExceptionInterface;

class Limit
{
Expand Down

0 comments on commit b9c0281

Please sign in to comment.