mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Adds exception
property to Request Lifecycle Events (#5721)
This commit is contained in:
parent
63d5f89db5
commit
c97f22c796
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user