This commit is contained in:
2026-07-31 08:32:26 +08:00
parent 63aed7981f
commit ec64c80563

View File

@@ -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)