init
This commit is contained in:
40
extend/Aether/PHP/Hyperf/Exception/BusinessException.php
Normal file
40
extend/Aether/PHP/Hyperf/Exception/BusinessException.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Aether\Exception;
|
||||
|
||||
use Hyperf\Server\Exception\ServerException;
|
||||
|
||||
class BusinessException extends ServerException
|
||||
{
|
||||
// 错误码常量(按业务模块划分)
|
||||
public const VALIDATION_ERROR = 400; // 参数验证失败
|
||||
public const AUTH_ERROR = 401; // 认证失败
|
||||
public const PERMISSION_DENY = 403; // 权限不足
|
||||
public const RESOURCE_NOT_FOUND = 404; // 资源不存在
|
||||
public const SCENE_NOT_FOUND = 400;
|
||||
|
||||
/**
|
||||
* 额外错误数据(如验证详情)
|
||||
*/
|
||||
protected ?array $errorData = null;
|
||||
|
||||
public function __construct(
|
||||
string $message,
|
||||
int $code = 500,
|
||||
?\Throwable $previous = null,
|
||||
?array $errorData = null
|
||||
) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->errorData = $errorData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取额外错误数据
|
||||
*/
|
||||
public function getErrorData(): ?array
|
||||
{
|
||||
return $this->errorData;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user