Skip to content

Commit bea7120

Browse files
authored
Merge pull request #24 from deliciousbrains/add-access-denied-exception
403 errors are now handled by a custom exception
2 parents 0566119 + 20bfef1 commit bea7120

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Endpoints/Endpoint.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace DeliciousBrains\SpinupWp\Endpoints;
44

5+
use DeliciousBrains\SpinupWp\Exceptions\AccessDeniedException;
56
use DeliciousBrains\SpinupWp\Exceptions\NotFoundException;
67
use DeliciousBrains\SpinupWp\Exceptions\RateLimitException;
78
use DeliciousBrains\SpinupWp\Exceptions\TimeoutException;
@@ -47,6 +48,10 @@ protected function handleRequestError(ResponseInterface $response): void
4748
throw new UnauthorizedException();
4849
}
4950

51+
if ($response->getStatusCode() === 403) {
52+
throw new AccessDeniedException();
53+
}
54+
5055
if ($response->getStatusCode() === 404) {
5156
throw new NotFoundException();
5257
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace DeliciousBrains\SpinupWp\Exceptions;
4+
5+
use Exception;
6+
7+
class AccessDeniedException extends Exception
8+
{
9+
public function __construct()
10+
{
11+
parent::__construct('Your API token does not have permission to that resource.', 403);
12+
}
13+
}

0 commit comments

Comments
 (0)