Compare commits
3 Commits
63aed7981f
...
d0acbeea51
| Author | SHA1 | Date | |
|---|---|---|---|
| d0acbeea51 | |||
| be71680b2a | |||
| ec64c80563 |
@@ -1,3 +1,6 @@
|
||||
# hyperf_micro_service_core_app
|
||||
|
||||
app微服务核心库,所有微服务均以本库为基础
|
||||
app微服务核心库,所有微服务均以本库为基础
|
||||
|
||||
### update
|
||||
composer update dhd/hyperf-micro-service-core
|
||||
@@ -62,7 +62,7 @@ class GatewayExceptionHandler extends ExceptionHandler
|
||||
$responseData = [
|
||||
'code' => $code,
|
||||
'message' => $message,
|
||||
'data' => null,
|
||||
'data' => method_exists($throwable, 'getData') ? $throwable->getData() : null,
|
||||
];
|
||||
|
||||
return $response
|
||||
|
||||
@@ -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