42 lines
804 B
PHP
42 lines
804 B
PHP
<?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;
|
|
}
|
|
}
|