<?php
|
namespace app\common\exception;
|
|
|
trait Error
|
{
|
protected $HxError = NULL;
|
|
|
/**
|
* 设置错误
|
* @param $message
|
* @param int $code
|
* @return bool
|
*/
|
protected function setError($message, int $code = 1): bool
|
{
|
if (gettype($message) == 'object')
|
{
|
if (!($message instanceof ApiException) && $message instanceof \Exception) $message = new ApiException($message->getMessage(), $message->getCode());
|
}
|
else {
|
if (gettype($message) != 'string') $message = (string)$message;
|
|
$message = new ApiException($message, $code);
|
}
|
|
$this->HxError = $message;
|
|
return false;
|
}
|
|
|
/**
|
* 获取错误
|
*
|
* @return ApiException
|
*/
|
public function getError(): ApiException
|
{
|
return $this->HxError;
|
}
|
|
}
|