mirror of
http://124.126.16.154:8888/singularity/HyperfDevelopmentKit.git
synced 2026-01-15 00:35:08 +08:00
feat(common.exception): 对验证的exception添加了 message 的处理
This commit is contained in:
@@ -77,7 +77,7 @@ class CommonErrorCode extends AbstractConstants
|
||||
|
||||
/**
|
||||
* 参数非法.
|
||||
* @Message("common_error.params.format_common_error")
|
||||
* @Message("common_error.params.format_error")
|
||||
*/
|
||||
public const FORMATTER_ERROR = 1020001;
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ class DbException extends HttpException
|
||||
{
|
||||
public function __construct(
|
||||
int $code = CommonErrorCode::PROGRAM_SQL_ERROR,
|
||||
?string $message = null,
|
||||
public string $sql = '',
|
||||
Throwable $previous = null
|
||||
) {
|
||||
@@ -23,7 +24,7 @@ class DbException extends HttpException
|
||||
}
|
||||
parent::__construct(
|
||||
RFC7231::INTERNAL_SERVER_ERROR,
|
||||
CommonErrorCode::getMessage($code),
|
||||
$message ?? CommonErrorCode::getMessage($code),
|
||||
$code,
|
||||
$previous
|
||||
);
|
||||
|
||||
@@ -156,9 +156,10 @@ class CommonHandler extends ExceptionHandler
|
||||
}
|
||||
if ($throwable instanceof ValidateException) {
|
||||
$code = $throwable->getCode();
|
||||
$message = $throwable->getMessage();
|
||||
$data = [
|
||||
$code_name => $code,
|
||||
$message_name => CommonErrorCode::getMessage($code, [
|
||||
$message_name => $message ?? CommonErrorCode::getMessage($code, [
|
||||
'param' => $throwable->getFieldName(),
|
||||
]),
|
||||
];
|
||||
|
||||
@@ -14,6 +14,7 @@ class ValidateException extends HttpException
|
||||
{
|
||||
public function __construct(
|
||||
int $code = CommonErrorCode::FORMATTER_ERROR,
|
||||
?string $message = null,
|
||||
private string $field = '',
|
||||
private mixed $currentValue = null,
|
||||
private array $availableValue = [],
|
||||
@@ -25,7 +26,13 @@ class ValidateException extends HttpException
|
||||
}
|
||||
parent::__construct(
|
||||
RFC4918::UNPROCESSABLE_ENTITY,
|
||||
CommonErrorCode::getMessage($code),
|
||||
$message ??
|
||||
CommonErrorCode::getMessage(
|
||||
$code,
|
||||
[
|
||||
'param' => $this->getFieldName(),
|
||||
]
|
||||
),
|
||||
$code,
|
||||
$previous
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user