diff --git a/composer.json b/composer.json index 77f6f4b..d59be41 100644 --- a/composer.json +++ b/composer.json @@ -14,8 +14,8 @@ "php": ">=7.1", "nikic/fast-route": "^1.3", "react/async": "^4 || ^3", - "react/http": "^1.7", - "react/promise": "^2.7" + "react/http": "^1.8@dev || ^1.7", + "react/promise": "^3@dev || ^2.7" }, "require-dev": { "phpunit/phpunit": "^9.5 || ^7.5", diff --git a/src/ErrorHandler.php b/src/ErrorHandler.php index 39d691a..b70f53c 100644 --- a/src/ErrorHandler.php +++ b/src/ErrorHandler.php @@ -48,10 +48,13 @@ public function __invoke(ServerRequestInterface $request, callable $next) return $this->errorInvalidResponse($response); } }, function ($e) { + // Promise rejected, always a `\Throwable` as of Promise v3 + assert($e instanceof \Throwable || !\method_exists(PromiseInterface::class, 'catch')); + if ($e instanceof \Throwable) { return $this->errorInvalidException($e); } else { - return $this->errorInvalidResponse(\React\Promise\reject($e)); + return $this->errorInvalidResponse(\React\Promise\reject($e)); // @codeCoverageIgnore } }); } elseif ($response instanceof \Generator) { diff --git a/tests/AppTest.php b/tests/AppTest.php index 481e52f..a3bfacf 100644 --- a/tests/AppTest.php +++ b/tests/AppTest.php @@ -1534,6 +1534,10 @@ public function testHandleRequestWithMatchingRouteReturnsPromiseWhichFulfillsWit public function testHandleRequestWithMatchingRouteReturnsPromiseWhichFulfillsWithInternalServerErrorResponseWhenHandlerReturnsPromiseWhichRejectsWithNull() { + if (method_exists(PromiseInterface::class, 'catch')) { + $this->markTestSkipped('Only supported for legacy Promise v2, Promise v3 already rejects with Throwable'); + } + $app = $this->createAppWithoutLogger(); $app->get('/users', function () { diff --git a/tests/ErrorHandlerTest.php b/tests/ErrorHandlerTest.php index 7acc3f0..95bef28 100644 --- a/tests/ErrorHandlerTest.php +++ b/tests/ErrorHandlerTest.php @@ -273,6 +273,10 @@ public function testInvokeWithHandlerReturningPromiseResolvingWithNullReturnsPro public function testInvokeWithHandlerReturningPromiseRejectingWithNullReturnsPromiseResolvingWithError500Response() { + if (method_exists(PromiseInterface::class, 'catch')) { + $this->markTestSkipped('Only supported for legacy Promise v2, Promise v3 already rejects with Throwable'); + } + $handler = new ErrorHandler(); $request = new ServerRequest('GET', 'http://example.com/');