update
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user