Skip to content

Commit beaf18d

Browse files
committed
refactor: split authentication and authorization exceptions
1 parent 5260f43 commit beaf18d

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/Client.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use GuzzleHttp\Client as GuzzleClient;
88
use GuzzleHttp\Exception\GuzzleException;
9+
use Illuminate\Auth\Access\AuthorizationException;
910
use PhpList\RestApiClient\Exception\ApiException;
1011
use PhpList\RestApiClient\Exception\AuthenticationException;
1112
use PhpList\RestApiClient\Exception\NotFoundException;
@@ -402,7 +403,14 @@ private function handleRawResponse(ResponseInterface $response): string
402403
private function handleErrorResponse(int $statusCode, array $data): never
403404
{
404405
throw match ($statusCode) {
405-
401, 403 => new AuthenticationException($data['message'] ?? 'Authentication failed', $statusCode),
406+
401 => new AuthenticationException(
407+
$data['message'] ?? 'Authentication failed',
408+
$statusCode,
409+
),
410+
403 => new AuthorizationException(
411+
$data['message'] ?? 'Access denied',
412+
$statusCode,
413+
),
406414
404 => new NotFoundException($data['message'] ?? 'Resource not found', $statusCode),
407415
400,422 => new ValidationException(
408416
message: $data['message'] ?? 'Validation failed',

0 commit comments

Comments
 (0)