diff --git a/src/Exceptions/ForbiddenException.php b/src/Exceptions/ForbiddenException.php index 8dd800b..2088866 100644 --- a/src/Exceptions/ForbiddenException.php +++ b/src/Exceptions/ForbiddenException.php @@ -8,8 +8,8 @@ use Throwable; /** - * This exception should be thrown when the requesting user does not have rights to perform a specific action on a - * requested resource. + * This exception should be thrown when the requesting user doesn't have + * the permission to perform a specific action on a requested resource. */ class ForbiddenException extends AbstractException { diff --git a/src/Exceptions/Interfaces/ExceptionInterface.php b/src/Exceptions/Interfaces/ExceptionInterface.php index 2c3e394..924869b 100644 --- a/src/Exceptions/Interfaces/ExceptionInterface.php +++ b/src/Exceptions/Interfaces/ExceptionInterface.php @@ -22,11 +22,6 @@ interface ExceptionInterface extends JsonSchemaErrorInterface 'title' => 'Resource Not Found', ]; - const RESOURCE_HANDLED_BY_3RD_PARTY = [ - 'code' => '10014', - 'title' => 'Resource Handled By 3rd Party', - ]; - const INVALID_JSON_SCHEMA = [ 'code' => '10003', 'title' => 'Invalid JSON Schema', @@ -82,6 +77,11 @@ interface ExceptionInterface extends JsonSchemaErrorInterface 'title' => 'Action not allowed.', ]; + const RESOURCE_HANDLED_BY_3RD_PARTY = [ + 'code' => '10014', + 'title' => 'Resource Handled By 3rd Party', + ]; + // External API related errors 13000 - 13999 const EXTERNAL_REQUEST_ERROR = [ 'code' => '13001', @@ -121,7 +121,7 @@ interface ExceptionInterface extends JsonSchemaErrorInterface const AUTH_MISSING_SCOPE = [ 'code' => '14004', - 'title' => 'Access Token Is Invalid', + 'title' => 'Missing scope in access token', ]; const AUTH_SERVER_EXCEPTION = [ diff --git a/src/Exceptions/MissingScopeException.php b/src/Exceptions/MissingScopeException.php index bc6a4ac..39853e4 100644 --- a/src/Exceptions/MissingScopeException.php +++ b/src/Exceptions/MissingScopeException.php @@ -8,6 +8,10 @@ use Symfony\Component\HttpFoundation\Response; use Throwable; +/** + * This exception should be thrown when the requesting user + * doesn't have the required scopes in his (client) access token + */ class MissingScopeException extends AbstractException { use EnumTrait; @@ -16,10 +20,10 @@ public function __construct(array $scopeSlugs, Throwable $previous = null) { $scopeStrings = collect($scopeSlugs) ->map(fn (mixed $scopeSlug) => $this->getEnumValue($scopeSlug)) - ->toArray(); + ->join(', '); parent::__construct( - 'The used access token does not contain the required scope(s): ' . implode(', ', $scopeStrings) . '.', + 'The used access token does not contain the required scope(s): ' . $scopeStrings . '.', self::AUTH_MISSING_SCOPE, Response::HTTP_FORBIDDEN, $previous, diff --git a/src/Exceptions/ResourceNotFoundException.php b/src/Exceptions/ResourceNotFoundException.php index 3f983d3..61d02bb 100644 --- a/src/Exceptions/ResourceNotFoundException.php +++ b/src/Exceptions/ResourceNotFoundException.php @@ -9,6 +9,10 @@ use Throwable; use UnitEnum; +/** + * This exception should be thrown when a user attempts to fetch a resource + * which he doesn't have access to based on his permissions + */ class ResourceNotFoundException extends AbstractException { use EnumTrait;