From 7f14a5ed4db96a1ace3a5bd584ebc1ce8be10c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 4 Aug 2021 16:02:13 +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 --- Server/Abstracts/PageNotFoundException.php | 21 +++++++++++++++++++++ Server/HTTPServerListener.php | 10 +++------- 2 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 Server/Abstracts/PageNotFoundException.php diff --git a/Server/Abstracts/PageNotFoundException.php b/Server/Abstracts/PageNotFoundException.php new file mode 100644 index 00000000..3e829973 --- /dev/null +++ b/Server/Abstracts/PageNotFoundException.php @@ -0,0 +1,21 @@ +HTTP 404 Not Found
Powered by Swoole', $code); + } + +} diff --git a/Server/HTTPServerListener.php b/Server/HTTPServerListener.php index dbbb4432..1a41e313 100644 --- a/Server/HTTPServerListener.php +++ b/Server/HTTPServerListener.php @@ -9,6 +9,7 @@ use HttpServer\Http\Request as HSRequest; use HttpServer\Route\Node; use HttpServer\Route\Router; use ReflectionException; +use Server\Abstracts\PageNotFoundException; use Server\Constrict\Response as CResponse; use Server\Events\OnAfterRequest; use Snowflake\Abstracts\Config; @@ -119,16 +120,11 @@ class HTTPServerListener extends Abstracts\Server try { $node = $this->router->find_path(HSRequest::create($request)); if (!($node instanceof Node)) { - throw new RequestException('

HTTP 404 Not Found


Powered by Swoole', 404); + throw new PageNotFoundException(404); } $responseData = $this->response->setContent($node->dispatch())->setStatusCode(200); } catch (Error | Throwable $exception) { - try { - $responseData = $this->exceptionHandler->emit($exception, $this->response); - } catch (Throwable $throwable) { - var_dump($throwable->getMessage()); - return; - } + $responseData = $this->exceptionHandler->emit($exception, $this->response); } finally { $response->end($responseData->configure($response)->getContent());