mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 11:19:56 +00:00
no message
This commit is contained in:
parent
c388fe373d
commit
6b72a309f5
@ -10,13 +10,18 @@ class ApiException extends RuntimeException
|
|||||||
*/
|
*/
|
||||||
protected $data;
|
protected $data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $writeLog = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ApiException constructor.
|
* ApiException constructor.
|
||||||
* @param string $msg
|
* @param string|array $msg
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @param int $code
|
* @param int $code
|
||||||
*/
|
*/
|
||||||
public function __construct($msg = '', $data = [], $code = 0)
|
public function __construct($msg = '', $data = [], $code = 0, $writeLog = true)
|
||||||
{
|
{
|
||||||
if (is_array($msg) && isset($msg['code'])) {
|
if (is_array($msg) && isset($msg['code'])) {
|
||||||
$code = $msg['code'];
|
$code = $msg['code'];
|
||||||
@ -24,6 +29,7 @@ class ApiException extends RuntimeException
|
|||||||
$msg = $msg['msg'];
|
$msg = $msg['msg'];
|
||||||
}
|
}
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
|
$this->writeLog = $writeLog && $code !== -1;
|
||||||
parent::__construct($msg, $code);
|
parent::__construct($msg, $code);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,4 +40,12 @@ class ApiException extends RuntimeException
|
|||||||
{
|
{
|
||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isWriteLog(): bool
|
||||||
|
{
|
||||||
|
return $this->writeLog;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,7 +74,7 @@ class Handler extends ExceptionHandler
|
|||||||
public function report(Throwable $e)
|
public function report(Throwable $e)
|
||||||
{
|
{
|
||||||
if ($e instanceof ApiException) {
|
if ($e instanceof ApiException) {
|
||||||
if ($e->getCode() !== -1) {
|
if ($e->isWriteLog()) {
|
||||||
Log::error($e->getMessage(), [
|
Log::error($e->getMessage(), [
|
||||||
'code' => $e->getCode(),
|
'code' => $e->getCode(),
|
||||||
'data' => $e->getData(),
|
'data' => $e->getData(),
|
||||||
|
|||||||
@ -54,7 +54,7 @@ class Apps
|
|||||||
'search' => 'ZincSearch',
|
'search' => 'ZincSearch',
|
||||||
default => $appId,
|
default => $appId,
|
||||||
};
|
};
|
||||||
throw new ApiException("应用「{$name}」未安装");
|
throw new ApiException("应用「{$name}」未安装", [], 0, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user