diff --git a/src/Exceptions/ForbiddenException.php b/src/Exceptions/ForbiddenException.php new file mode 100644 index 0000000..27ead79 --- /dev/null +++ b/src/Exceptions/ForbiddenException.php @@ -0,0 +1,10 @@ +getBody(), true)); } + if ($response->getStatusCode() === 403) { + throw new ForbiddenException((string) $response->getBody()); + } + if ($response->getStatusCode() == 404) { throw new NotFoundException; } diff --git a/tests/ForgeSDKTest.php b/tests/ForgeSDKTest.php index b39fcd1..cb1a609 100644 --- a/tests/ForgeSDKTest.php +++ b/tests/ForgeSDKTest.php @@ -5,6 +5,7 @@ use GuzzleHttp\Client; use GuzzleHttp\Psr7\Response; use Laravel\Forge\Exceptions\FailedActionException; +use Laravel\Forge\Exceptions\ForbiddenException; use Laravel\Forge\Exceptions\NotFoundException; use Laravel\Forge\Exceptions\RateLimitExceededException; use Laravel\Forge\Exceptions\TimeoutException; @@ -76,6 +77,19 @@ public function test_handling_404_errors() $forge->recipes(); } + public function test_handling_forbidden_requests(): void + { + $this->expectException(ForbiddenException::class); + + $forge = new Forge('123', $http = Mockery::mock(Client::class)); + + $http->shouldReceive('request')->once()->with('GET', 'recipes', [])->andReturn( + new Response(403) + ); + + $forge->recipes(); + } + public function test_handling_failed_action_errors() { $forge = new Forge('123', $http = Mockery::mock(Client::class));