diff --git a/Server/ExceptionHandlerDispatcher.php b/Server/ExceptionHandlerDispatcher.php index 12fd5e98..aa6320f5 100644 --- a/Server/ExceptionHandlerDispatcher.php +++ b/Server/ExceptionHandlerDispatcher.php @@ -5,6 +5,7 @@ namespace Server; use Server\Constrict\Response; use Server\Constrict\Response as CResponse; +use Throwable; /** * @@ -14,15 +15,19 @@ class ExceptionHandlerDispatcher implements ExceptionHandlerInterface /** - * @param \Throwable $exception + * @param Throwable $exception * @param CResponse $response - * @return Response + * @return CResponse|\HttpServer\Http\Response */ - public function emit(\Throwable $exception, Response $response): Response + public function emit(Throwable $exception, Response $response): Response|\HttpServer\Http\Response { + if ($exception->getCode() == 404) { + return $response->setContent($exception->getMessage()) + ->setFormat(CResponse::HTML) + ->setStatusCode(404); + } $code = $exception->getCode() == 0 ? 500 : $exception->getCode(); - $data = $code == 404 ? $exception->getMessage() : jTraceEx($exception, null, true); - return $response->setContent($data) + return $response->setContent(jTraceEx($exception, null, true)) ->setFormat(CResponse::HTML) ->setStatusCode($code); } diff --git a/Server/ExceptionHandlerInterface.php b/Server/ExceptionHandlerInterface.php index 5f7ca691..4a8dfd60 100644 --- a/Server/ExceptionHandlerInterface.php +++ b/Server/ExceptionHandlerInterface.php @@ -2,7 +2,9 @@ namespace Server; +use HttpServer\Http\Response as SResponse; use Server\Constrict\Response; +use Throwable; /** * @@ -12,10 +14,10 @@ interface ExceptionHandlerInterface /** - * @param \Throwable $exception + * @param Throwable $exception * @param Response $response - * @return Response + * @return Response|SResponse */ - public function emit(\Throwable $exception, Response $response): Response; + public function emit(Throwable $exception, Response $response): Response|SResponse; } diff --git a/function.php b/function.php index 72e1c022..0eee08ec 100644 --- a/function.php +++ b/function.php @@ -7,20 +7,19 @@ use Annotation\Annotation; use HttpServer\Http\Context; use HttpServer\Http\HttpParams; use HttpServer\Http\Request; -use HttpServer\Http\Response; use HttpServer\Route\Router; use JetBrains\PhpStorm\Pure; use Snowflake\Abstracts\Config; use Snowflake\Aop; use Snowflake\Application; use Snowflake\Core\ArrayAccess; -use Snowflake\Core\Json; use Snowflake\Error\Logger; use Snowflake\Event; use Snowflake\Exception\ConfigException; use Snowflake\Exception\NotFindClassException; use Snowflake\Snowflake; use Swoole\WebSocket\Server; +use Server\Constrict\Response; if (!function_exists('make')) { @@ -55,6 +54,11 @@ if (!function_exists('make')) { if (!function_exists('workerName')) { + + /** + * @param $worker_id + * @return string + */ function workerName($worker_id) { return $worker_id >= Snowflake::app()->getSwoole()->setting['worker_num'] ? 'Task' : 'Worker';