diff --git a/src/Exception/Handler/GatewayExceptionHandler.php b/src/Exception/Handler/GatewayExceptionHandler.php index 4bae17e..378cc59 100644 --- a/src/Exception/Handler/GatewayExceptionHandler.php +++ b/src/Exception/Handler/GatewayExceptionHandler.php @@ -15,6 +15,7 @@ use Psr\Http\Message\ResponseInterface; use Hyperf\HttpMessage\Stream\SwooleStream; use Hyperf\HttpServer\Contract\RequestInterface; +use Hyperf\RpcClient\Exception\RequestException; use Dhd\Micro\Core\Exception\BusinessException; use Dhd\Micro\Core\Trait\RpcContextTrait; @@ -43,12 +44,16 @@ class GatewayExceptionHandler extends ExceptionHandler } $request = Util::get(RequestInterface::class); - Util::logger()->setErrorStatus(!($throwable instanceof BusinessException)) + Util::logger() + ->setErrorStatus( + !($throwable instanceof BusinessException) + && !($throwable instanceof RequestException) + ) ->setMessage($message) ->setThrowable($throwable) ->setTraceId($traceId) ->setContext([ - 'url' => $request->getUri(), + 'url' => $request->url(), 'method' => $request->getMethod(), 'request_data' => $request->all(), ]) diff --git a/src/Exception/Handler/JsonRpcBusinessExceptionHandler.php b/src/Exception/Handler/JsonRpcBusinessExceptionHandler.php index dfce0d7..374e0d6 100644 --- a/src/Exception/Handler/JsonRpcBusinessExceptionHandler.php +++ b/src/Exception/Handler/JsonRpcBusinessExceptionHandler.php @@ -15,7 +15,9 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Hyperf\HttpMessage\Stream\SwooleStream; +use Hyperf\RpcClient\Exception\RequestException; use Dhd\Micro\Core\Exception\BusinessException; +use Dhd\Micro\Core\Exception\ValidateException; use Dhd\Micro\Core\Trait\RpcContextTrait; @@ -36,7 +38,12 @@ class JsonRpcBusinessExceptionHandler extends ExceptionHandler $code = $throwable->getCode() ?? 500; $message = $throwable->getMessage() ?? '服务器内部错误'; - Util::logger()->setErrorStatus(!($throwable instanceof BusinessException)) + Util::logger() + ->setErrorStatus( + !($throwable instanceof BusinessException) + && !($throwable instanceof ValidateException) + && !($throwable instanceof RequestException) + ) ->setMessage($message) ->setThrowable($throwable) ->setTraceId($traceId) diff --git a/src/Exception/ValidateException.php b/src/Exception/ValidateException.php new file mode 100644 index 0000000..1000145 --- /dev/null +++ b/src/Exception/ValidateException.php @@ -0,0 +1,21 @@ +