异常
This commit is contained in:
41
extend/Aether/PHP/Hyperf/RpcException/BusinessException.php
Normal file
41
extend/Aether/PHP/Hyperf/RpcException/BusinessException.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Aether\RpcException;
|
||||
|
||||
use Hyperf\Server\Exception\ServerException;
|
||||
use Throwable;
|
||||
|
||||
class BusinessException extends ServerException
|
||||
{
|
||||
/**
|
||||
* @var int 错误码
|
||||
*/
|
||||
protected $code;
|
||||
|
||||
/**
|
||||
* @var array 额外数据
|
||||
*/
|
||||
protected array $data = [];
|
||||
|
||||
public function __construct(string $message = '', int $code = ErrorCode::SYSTEM_ERROR, array $data = [], ?Throwable $previous = null)
|
||||
{
|
||||
if (empty($message)) {
|
||||
$message = ErrorCode::getMessage($code);
|
||||
}
|
||||
|
||||
$this->code = $code;
|
||||
$this->data = $data;
|
||||
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取额外数据.
|
||||
*/
|
||||
public function getData(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user