From 84a1a182fb5df3ea12f4a61adedea5ae39491e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 9 Sep 2020 20:08:09 +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 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/HttpServer/Events/OnRequest.php b/HttpServer/Events/OnRequest.php index 97c938fc..28639de5 100644 --- a/HttpServer/Events/OnRequest.php +++ b/HttpServer/Events/OnRequest.php @@ -36,6 +36,21 @@ class OnRequest extends Callback public function onHandler(Request $request, Response $response) { try { + register_shutdown_function(function () use ($response) { + $error = error_get_last(); + switch ($error['type'] ?? null) { + case E_ERROR : + case E_PARSE : + case E_CORE_ERROR : + case E_COMPILE_ERROR : + // log or send: + // error_log($message); + // $server->send($fd, $error['message']); + $response->status(500); + $response->end($error['message']); + break; + } + }); /** @var HRequest $sRequest */ [$sRequest, $sResponse] = static::setContext($request, $response); if ($sRequest->is('favicon.ico')) {