From 692bdf1cffc23c91f3df5b28e199e3d3432c5795 Mon Sep 17 00:00:00 2001 From: Markus Wolff Date: Wed, 2 Aug 2023 11:52:05 +0200 Subject: [PATCH 1/4] Remove references to GuzzleHttp\Promise\rejection_for (Guzzle 7.7 compatibility) Fixes: https://github.com/gmponos/guzzle-log-middleware/issues/48 --- src/LogMiddleware.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LogMiddleware.php b/src/LogMiddleware.php index 0e54e47..e80d550 100644 --- a/src/LogMiddleware.php +++ b/src/LogMiddleware.php @@ -112,11 +112,11 @@ private function handleFailure(RequestInterface $request, array $options): calla return function (\Exception $reason) use ($request, $options) { if ($reason instanceof RequestException && $reason->hasResponse() === true) { $this->handler->log($this->logger, $request, $reason->getResponse(), $reason, $this->stats, $options); - return \GuzzleHttp\Promise\rejection_for($reason); + return new \GuzzleHttp\Promise\RejectedPromise($reason); } $this->handler->log($this->logger, $request, null, $reason, $this->stats, $options); - return \GuzzleHttp\Promise\rejection_for($reason); + return new \GuzzleHttp\Promise\RejectedPromise($reason); }; } From 7bb4ace07202c8894463db7129b54992b8dc37f8 Mon Sep 17 00:00:00 2001 From: Markus Wolff Date: Wed, 2 Aug 2023 11:59:23 +0200 Subject: [PATCH 2/4] Use Create::rejectionFor() in favour of direct instance creation Fixes: https://github.com/gmponos/guzzle-log-middleware/issues/48 --- src/LogMiddleware.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LogMiddleware.php b/src/LogMiddleware.php index e80d550..4e2b49d 100644 --- a/src/LogMiddleware.php +++ b/src/LogMiddleware.php @@ -112,11 +112,11 @@ private function handleFailure(RequestInterface $request, array $options): calla return function (\Exception $reason) use ($request, $options) { if ($reason instanceof RequestException && $reason->hasResponse() === true) { $this->handler->log($this->logger, $request, $reason->getResponse(), $reason, $this->stats, $options); - return new \GuzzleHttp\Promise\RejectedPromise($reason); + return \GuzzleHttp\Promise\Create::rejectionFor($reason); } $this->handler->log($this->logger, $request, null, $reason, $this->stats, $options); - return new \GuzzleHttp\Promise\RejectedPromise($reason); + return \GuzzleHttp\Promise\Create::rejectionFor($reason); }; } From 72f905c76bc27f2e9418971bac9cfdce21804af1 Mon Sep 17 00:00:00 2001 From: Markus Wolff Date: Wed, 2 Aug 2023 12:08:36 +0200 Subject: [PATCH 3/4] Exchange deprecated PSR TestLogger with colinodell/psr-testlogger --- composer.json | 1 + tests/AbstractLoggerMiddlewareTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 79ec4d8..194652b 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "psr/log": "^1.1 || ^2.0 || ^3.0" }, "require-dev": { + "colinodell/psr-testlogger": "^1.2", "phpstan/phpstan": "~0.12.32", "phpstan/phpstan-phpunit": "^0.12.11", "phpstan/phpstan-strict-rules": "^0.12.2", diff --git a/tests/AbstractLoggerMiddlewareTest.php b/tests/AbstractLoggerMiddlewareTest.php index 3017258..704c985 100644 --- a/tests/AbstractLoggerMiddlewareTest.php +++ b/tests/AbstractLoggerMiddlewareTest.php @@ -15,7 +15,7 @@ use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; -use Psr\Log\Test\TestLogger; +use ColinODell\PsrTestLogger\TestLogger; abstract class AbstractLoggerMiddlewareTest extends TestCase { From 4b77cf53f72a6f7d8e7039ac9ccb7023f6947a55 Mon Sep 17 00:00:00 2001 From: ossycodes Date: Tue, 29 Aug 2023 09:47:43 +0100 Subject: [PATCH 4/4] GuzzleHandler now accepts errors as well as exceptions on failure; errors are added to the body of the RejectionException from the promise --- src/LogMiddleware.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LogMiddleware.php b/src/LogMiddleware.php index 4e2b49d..3f3e635 100644 --- a/src/LogMiddleware.php +++ b/src/LogMiddleware.php @@ -109,7 +109,7 @@ private function handleSuccess(RequestInterface $request, array $options): calla */ private function handleFailure(RequestInterface $request, array $options): callable { - return function (\Exception $reason) use ($request, $options) { + return function ($reason) use ($request, $options) { if ($reason instanceof RequestException && $reason->hasResponse() === true) { $this->handler->log($this->logger, $request, $reason->getResponse(), $reason, $this->stats, $options); return \GuzzleHttp\Promise\Create::rejectionFor($reason);