From 122f43d687f80708ef1dd82fc13b5b54a0346ce1 Mon Sep 17 00:00:00 2001 From: Stefanius Date: Thu, 2 May 2024 11:04:48 +0200 Subject: [PATCH 1/3] Improved exceptions messages --- src/Client.php | 8 ++++---- src/Exceptions/FailedActionException.php | 10 +--------- src/Exceptions/NotFoundException.php | 8 +------- src/Exceptions/UnauthorizedException.php | 8 +------- 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/Client.php b/src/Client.php index f841a2f..ec1b16f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -162,17 +162,17 @@ protected function handleRequestError(ResponseInterface $response) } if ($response->getStatusCode() == 404) { - throw new NotFoundException(); + throw new NotFoundException((string) $response->getBody(), $response->getStatusCode()); } if ($response->getStatusCode() == 401 || $response->getStatusCode() == 403) { - throw new UnauthorizedException(); + throw new UnauthorizedException((string) $response->getBody(), $response->getStatusCode()); } if ($response->getStatusCode() == 400) { - throw new FailedActionException((string) $response->getBody()); + throw new FailedActionException((string) $response->getBody(), $response->getStatusCode()); } - throw new Exception((string) $response->getStatusCode()); + throw new Exception((string) $response->getBody(), $response->getStatusCode()); } } diff --git a/src/Exceptions/FailedActionException.php b/src/Exceptions/FailedActionException.php index 82a0eee..612ad13 100644 --- a/src/Exceptions/FailedActionException.php +++ b/src/Exceptions/FailedActionException.php @@ -4,13 +4,5 @@ class FailedActionException extends Exception { - /** - * Create a new exception instance. - * - * @param string $message - */ - public function __construct($message) - { - parent::__construct($message); - } + // } diff --git a/src/Exceptions/NotFoundException.php b/src/Exceptions/NotFoundException.php index c1f8b7a..fffab6a 100644 --- a/src/Exceptions/NotFoundException.php +++ b/src/Exceptions/NotFoundException.php @@ -4,11 +4,5 @@ class NotFoundException extends Exception { - /** - * Create a new exception instance. - */ - public function __construct() - { - parent::__construct('The resource you are looking for could not be found.'); - } + // } diff --git a/src/Exceptions/UnauthorizedException.php b/src/Exceptions/UnauthorizedException.php index 2b9904a..75b70ee 100644 --- a/src/Exceptions/UnauthorizedException.php +++ b/src/Exceptions/UnauthorizedException.php @@ -4,11 +4,5 @@ class UnauthorizedException extends Exception { - /** - * Create a new exception instance. - */ - public function __construct() - { - parent::__construct(); - } + // } From 636fb74d77e556cb4c8a8f6a723c5c4935a3c7c4 Mon Sep 17 00:00:00 2001 From: Stefanius Date: Thu, 2 May 2024 11:12:58 +0200 Subject: [PATCH 2/3] Fix unittest --- tests/ProjectsTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ProjectsTest.php b/tests/ProjectsTest.php index cd2b5b6..623fee1 100644 --- a/tests/ProjectsTest.php +++ b/tests/ProjectsTest.php @@ -104,7 +104,6 @@ public function it_should_throw_a_unauthorized_exception_when_client_lacks_autho $service->shouldReceive('request')->once()->andReturn($response = Mockery::mock('Psr\Http\Message\ResponseInterface')); $response->shouldReceive('getStatusCode')->andReturn(401); - $response->shouldReceive('getBody')->andReturnNull(); $response->shouldReceive('getBody')->andReturn(\GuzzleHttp\Psr7\Utils::streamFor()); $this->expectException(UnauthorizedException::class); From d7f58d9da2daf4b581f018686572f1fe5c7bb48a Mon Sep 17 00:00:00 2001 From: Stefanius Date: Thu, 2 May 2024 13:58:27 +0200 Subject: [PATCH 3/3] Some rework --- src/Client.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index ec1b16f..8b54d82 100644 --- a/src/Client.php +++ b/src/Client.php @@ -150,6 +150,7 @@ protected function request($verb, $uri, array $payload = []) * * @throws \TestMonitor\Mantis\Exceptions\ValidationException * @throws \TestMonitor\Mantis\Exceptions\NotFoundException + * @throws \TestMonitor\Mantis\Exceptions\UnauthorizedException * @throws \TestMonitor\Mantis\Exceptions\FailedActionException * @throws \Exception * @@ -173,6 +174,6 @@ protected function handleRequestError(ResponseInterface $response) throw new FailedActionException((string) $response->getBody(), $response->getStatusCode()); } - throw new Exception((string) $response->getBody(), $response->getStatusCode()); + throw new Exception((string) $response->getStatusCode()); } }