This commit is contained in:
2026-08-05 15:24:46 +08:00
parent 30c531afbb
commit e5dd2b81f1

View File

@@ -32,25 +32,21 @@ class GatewayExceptionHandler extends ExceptionHandler
$this->stopPropagation(); // 阻止异常冒泡
$traceId = $this->getTraceId();
$isError = !($throwable instanceof BusinessException)
&& !($throwable instanceof ValidateException)
&& !($throwable instanceof RequestException);
$code = 500;
$message = '服务器内部错误';
if (($throwable instanceof BusinessException)) {
$code = $throwable->getCode();
$message = $throwable->getMessage();
if ($isError) {
$code = 500;
$message = '服务器内部错误';
} else {
$code = $throwable->getCode() ?: 500;
$message = $throwable->getMessage() ?: '服务异常,请稍后重试';
$code = $throwable->getCode() ?? 500;
$message = $throwable->getMessage() ?? '服务器内部错误';
}
$request = Util::get(RequestInterface::class);
Util::logger()
->setErrorStatus(
!($throwable instanceof BusinessException)
&& !($throwable instanceof ValidateException)
&& !($throwable instanceof RequestException)
)
->setErrorStatus($isError)
->setMessage($message)
->setThrowable($throwable)
->setTraceId($traceId)