From 64aec80889b060ca39e4d14c5d639c6af277c3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A0=82=E5=90=89=E8=AF=83=E5=BE=B7=E6=8B=89=E6=9B=BC?= =?UTF-8?q?=E6=9F=A5=E7=9A=84=E8=8B=B1=E8=B1=AA?= Date: Thu, 6 Aug 2026 15:34:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=E5=99=A8?= =?UTF-8?q?=E5=85=BC=E5=AE=B9ModelNotFoundException=E8=BF=94=E5=9B=9E404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Handler/JsonRpcBusinessExceptionHandler.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Exception/Handler/JsonRpcBusinessExceptionHandler.php b/src/Exception/Handler/JsonRpcBusinessExceptionHandler.php index 590d374..7f5d0cb 100644 --- a/src/Exception/Handler/JsonRpcBusinessExceptionHandler.php +++ b/src/Exception/Handler/JsonRpcBusinessExceptionHandler.php @@ -18,6 +18,7 @@ use Hyperf\HttpMessage\Stream\SwooleStream; use Hyperf\RpcClient\Exception\RequestException; use Dhd\Micro\Core\Exception\BusinessException; use Dhd\Micro\Core\Exception\ValidateException; +use Hyperf\Database\Model\ModelNotFoundException; use Dhd\Micro\Core\Trait\RpcContextTrait; @@ -36,9 +37,13 @@ class JsonRpcBusinessExceptionHandler extends ExceptionHandler $id = $request ? $request->getAttribute('request_id', null) : null; // Hyperf 注入的 ID $isError = !($throwable instanceof BusinessException) && !($throwable instanceof ValidateException) - && !($throwable instanceof RequestException); + && !($throwable instanceof RequestException) + && !($throwable instanceof ModelNotFoundException); - if ($isError) { + if ($throwable instanceof ModelNotFoundException) { + $code = 404; + $message = $throwable->getMessage(); + } elseif ($isError) { $code = 500; $message = '服务器内部错误'; } else {