This commit is contained in:
2025-12-31 00:19:29 +08:00
parent 34051feb87
commit 91e0fe8940
12 changed files with 569 additions and 66 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ class ExceptionHandlerDispatcher implements ExceptionHandlerInterface
*/
public function emit(Throwable $exception, object $response): ResponseInterface
{
error($exception);
\Kiri::getLogger()->json_log($exception);
$response->withContentType(ContentType::HTML)->withBody(new Stream(throwable($exception)));
if ($exception->getCode() == 404) {
return $response->withStatus(404);
+19 -25
View File
@@ -16,30 +16,24 @@ use Psr\Http\Server\RequestHandlerInterface;
class SessionMiddleware implements MiddlewareInterface
{
/**
* @param ServerRequestInterface $request
* @param RequestHandlerInterface $handler
* @return ResponseInterface
* @throws
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
// 启动 Session
Session::start($request);
try {
// 处理请求
$response = $handler->handle($request);
// 保存 Session
Session::save();
return $response;
} catch (\Throwable $e) {
// 即使出错也保存 Session
Session::save();
throw $e;
}
}
/**
* @param ServerRequestInterface $request
* @param RequestHandlerInterface $handler
* @return ResponseInterface
* @throws
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
// 启动 Session
Session::start($request);
// 处理请求
$response = $handler->handle($request);
// 保存 Session
Session::save();
return $response;
}
}