From ec64c80563fbed2d068719452dabf36b889e5dec Mon Sep 17 00:00:00 2001 From: zj Date: Fri, 31 Jul 2026 08:32:26 +0800 Subject: [PATCH] update --- .../JsonRpcBusinessExceptionHandler.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Exception/Handler/JsonRpcBusinessExceptionHandler.php b/src/Exception/Handler/JsonRpcBusinessExceptionHandler.php index 374e0d6..590d374 100644 --- a/src/Exception/Handler/JsonRpcBusinessExceptionHandler.php +++ b/src/Exception/Handler/JsonRpcBusinessExceptionHandler.php @@ -34,16 +34,20 @@ class JsonRpcBusinessExceptionHandler extends ExceptionHandler $request = Util::get(ServerRequestInterface::class); // 关键优化:从 Request 属性中动态获取 ID $id = $request ? $request->getAttribute('request_id', null) : null; // Hyperf 注入的 ID + $isError = !($throwable instanceof BusinessException) + && !($throwable instanceof ValidateException) + && !($throwable instanceof RequestException); - $code = $throwable->getCode() ?? 500; - $message = $throwable->getMessage() ?? '服务器内部错误'; + if ($isError) { + $code = 500; + $message = '服务器内部错误'; + } else { + $code = $throwable->getCode() ?? 500; + $message = $throwable->getMessage() ?? '服务器内部错误'; + } Util::logger() - ->setErrorStatus( - !($throwable instanceof BusinessException) - && !($throwable instanceof ValidateException) - && !($throwable instanceof RequestException) - ) + ->setErrorStatus($isError) ->setMessage($message) ->setThrowable($throwable) ->setTraceId($traceId)