|
|
@@ -15,7 +15,6 @@ namespace app\adminapi;
|
|
|
use crmeb\exceptions\AdminException;
|
|
|
use crmeb\exceptions\ApiException;
|
|
|
use crmeb\exceptions\AuthException;
|
|
|
-use think\exception\DbException;
|
|
|
use think\exception\Handle;
|
|
|
use think\exception\ValidateException;
|
|
|
use think\facade\Env;
|
|
|
@@ -25,6 +24,16 @@ use Throwable;
|
|
|
|
|
|
class AdminApiExceptionHandle extends Handle
|
|
|
{
|
|
|
+ /**
|
|
|
+ * 不需要记录信息(日志)的异常类列表
|
|
|
+ * @var array
|
|
|
+ */
|
|
|
+ protected $ignoreReport = [
|
|
|
+ ValidateException::class,
|
|
|
+ AuthException::class,
|
|
|
+ AdminException::class,
|
|
|
+ ApiException::class,
|
|
|
+ ];
|
|
|
|
|
|
/**
|
|
|
* 记录异常信息(包括日志或者其它方式记录)
|
|
|
@@ -34,26 +43,28 @@ class AdminApiExceptionHandle extends Handle
|
|
|
*/
|
|
|
public function report(Throwable $exception):void
|
|
|
{
|
|
|
- $data = [
|
|
|
- 'file' => $exception->getFile(),
|
|
|
- 'line' => $exception->getLine(),
|
|
|
- 'message' => $this->getMessage($exception),
|
|
|
- 'code' => $this->getCode($exception),
|
|
|
- ];
|
|
|
+ if (!$this->isIgnoreReport($exception)) {
|
|
|
+ $data = [
|
|
|
+ 'file' => $exception->getFile(),
|
|
|
+ 'line' => $exception->getLine(),
|
|
|
+ 'message' => $this->getMessage($exception),
|
|
|
+ 'code' => $this->getCode($exception),
|
|
|
+ ];
|
|
|
|
|
|
- //日志内容
|
|
|
- $log = [
|
|
|
- request()->adminId(), //管理员ID
|
|
|
- request()->ip(), //客户ip
|
|
|
- ceil(msectime() - (request()->time(true) * 1000)), //耗时(毫秒)
|
|
|
- request()->rule()->getMethod(), //请求类型
|
|
|
- str_replace("/", "", request()->rootUrl()), //应用
|
|
|
- request()->baseUrl(), //路由
|
|
|
- json_encode(request()->param(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), //请求参数
|
|
|
- json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), //报错数据
|
|
|
+ //日志内容
|
|
|
+ $log = [
|
|
|
+ request()->adminId(), //管理员ID
|
|
|
+ request()->ip(), //客户ip
|
|
|
+ ceil(msectime() - (request()->time(true) * 1000)), //耗时(毫秒)
|
|
|
+ request()->rule()->getMethod(), //请求类型
|
|
|
+ str_replace("/", "", request()->rootUrl()), //应用
|
|
|
+ request()->baseUrl(), //路由
|
|
|
+ json_encode(request()->param(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), //请求参数
|
|
|
+ json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), //报错数据
|
|
|
|
|
|
- ];
|
|
|
- Log::write(implode("|", $log), "error");
|
|
|
+ ];
|
|
|
+ Log::write(implode("|", $log), "error");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|