From e34b57703196a9ac43ff88d25d379202b2e57d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 7 Jan 2021 14:09:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Events/OnRequest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/HttpServer/Events/OnRequest.php b/HttpServer/Events/OnRequest.php index ca9b5a57..e213303c 100644 --- a/HttpServer/Events/OnRequest.php +++ b/HttpServer/Events/OnRequest.php @@ -10,6 +10,7 @@ use HttpServer\Exception\ExitException; use HttpServer\Http\Request as HRequest; use HttpServer\Http\Response as HResponse; use ReflectionException; +use Snowflake\Core\Json; use Snowflake\Event; use Snowflake\Exception\ComponentException; use Snowflake\Exception\NotFindClassException; @@ -32,22 +33,21 @@ class OnRequest extends Callback * @return void * @throws Exception */ - public function onHandler(Request $request, Response $response) + public function onHandler(Request $request, Response $response): mixed { try { [$req, $rep] = static::create($request, $response); if ($req->is('favicon.ico')) { - \send(null, 404); - } else { - \router()->dispatch(); + return \send(null, 404); } + \router()->dispatch(); } catch (ExitException | Error | \Throwable $exception) { if ($exception instanceof ExitException) { - \send($exception->getMessage(), $exception->getCode()); - } else { - $this->sendErrorMessage($exception); + return \send($exception->getMessage(), $exception->getCode()); } + $this->sendErrorMessage($exception); } finally { + write(Json::encode(get_object_vars($request)), 'request'); $this->onAfter(); } }