Adds exception property to Request Lifecycle Events (#5721)

This commit is contained in:
Deeka Wong 2023-05-15 09:29:36 +08:00 committed by GitHub
parent 63d5f89db5
commit c97f22c796
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View File

@ -1,5 +1,9 @@
# v3.0.21 - TBD
## Added
[#5721](https://github.com/hyperf/hyperf/pull/5721) Added `exception` property to Request Lifecycle Events.
# v3.0.20 - 2023-05-12
## Added

View File

@ -13,10 +13,11 @@ namespace Hyperf\HttpServer\Event;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Throwable;
abstract class Event
{
public function __construct(public ?ServerRequestInterface $request, public ?ResponseInterface $response)
public function __construct(public ?ServerRequestInterface $request, public ?ResponseInterface $response, public ?Throwable $exception = null)
{
}
}

View File

@ -108,9 +108,9 @@ class Server implements OnRequestInterface, MiddlewareInitializerInterface
});
} finally {
if (isset($psr7Request) && $this->option?->isEnableRequestLifecycle()) {
defer(fn () => $this->event?->dispatch(new RequestTerminated($psr7Request, $psr7Response ?? null)));
defer(fn () => $this->event?->dispatch(new RequestTerminated($psr7Request, $psr7Response ?? null, $throwable ?? null)));
$this->event?->dispatch(new RequestHandled($psr7Request, $psr7Response ?? null));
$this->event?->dispatch(new RequestHandled($psr7Request, $psr7Response ?? null, $throwable ?? null));
}
// Send the Response to client.