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