From afd384a52a83a28f08f63f455a6288e34a386e39 Mon Sep 17 00:00:00 2001 From: Aether Date: Fri, 26 Sep 2025 17:27:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=95=8A=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/Aether/PHP/Hyperf/GlobalExceptionHandler.php | 4 ++++ extend/Aether/PHP/Hyperf/RpcExceptionHandler.php | 7 ++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/extend/Aether/PHP/Hyperf/GlobalExceptionHandler.php b/extend/Aether/PHP/Hyperf/GlobalExceptionHandler.php index 6a977de..dcd5cb0 100644 --- a/extend/Aether/PHP/Hyperf/GlobalExceptionHandler.php +++ b/extend/Aether/PHP/Hyperf/GlobalExceptionHandler.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Aether; use Aether\Exception\BusinessException; +use Aether\Exception\ValidationFailedException; use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\Database\Model\ModelNotFoundException; use Hyperf\ExceptionHandler\ExceptionHandler; @@ -26,6 +27,9 @@ class GlobalExceptionHandler extends ExceptionHandler public function handle(Throwable $throwable, ResponseInterface $response): MessageInterface|ResponseInterface { + if ($throwable instanceof ValidationFailedException) { + return $response->withBody(new SwooleStream($throwable->getMessage())); + } // 处理业务异常 if ($throwable instanceof BusinessException) { $data = [ diff --git a/extend/Aether/PHP/Hyperf/RpcExceptionHandler.php b/extend/Aether/PHP/Hyperf/RpcExceptionHandler.php index ddaa1a0..e43240c 100644 --- a/extend/Aether/PHP/Hyperf/RpcExceptionHandler.php +++ b/extend/Aether/PHP/Hyperf/RpcExceptionHandler.php @@ -7,8 +7,6 @@ namespace Aether; use Hyperf\Context\Context; use Hyperf\ExceptionHandler\ExceptionHandler; use Hyperf\HttpMessage\Stream\SwooleStream; -use Psr\Container\ContainerExceptionInterface; -use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseInterface; use Throwable; @@ -16,10 +14,9 @@ use function Hyperf\Support\env; class RpcExceptionHandler extends ExceptionHandler { - /** - */ public function handle(Throwable $throwable, ResponseInterface $response): ResponseInterface - {var_dump($throwable->getMessage()); + { + var_dump($throwable->getMessage()); try { // 获取请求ID(用于日志追踪) $requestId = Context::get('request_id', '');