update
This commit is contained in:
@@ -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(),
|
||||
])
|
||||
|
||||
@@ -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)
|
||||
|
||||
21
src/Exception/ValidateException.php
Normal file
21
src/Exception/ValidateException.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 验证异常
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dhd\Micro\Core\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class ValidateException extends RuntimeException
|
||||
{
|
||||
protected $message = '参数验证错误';
|
||||
|
||||
public function __construct(string $message = '')
|
||||
{
|
||||
parent::__construct($message, 422);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@
|
||||
* 日志记录
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dhd\Micro\Core\Library;
|
||||
|
||||
use Hyperf\Logger\LoggerFactory;
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
* 公共函数库
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dhd\Micro\Core\Library;
|
||||
|
||||
use Hyperf\Context\ApplicationContext;
|
||||
use Hyperf\Collection\Arr;
|
||||
use Hyperf\Carbon\Carbon;
|
||||
use Hyperf\Logger\LoggerFactory;
|
||||
use Dhd\Micro\Core\Library\Logger;
|
||||
|
||||
final class Util
|
||||
|
||||
Reference in New Issue
Block a user