增加基础
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
namespace app;
|
||||
|
||||
use catcher\CatchResponse;
|
||||
use catcher\exceptions\FailedException;
|
||||
use catcher\exceptions\LoginFailedException;
|
||||
use catcher\exceptions\PermissionForbiddenException;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\exception\Handle;
|
||||
@@ -28,6 +31,12 @@ class ExceptionHandle extends Handle
|
||||
ValidateException::class,
|
||||
];
|
||||
|
||||
protected $catchExceptions = [
|
||||
FailedException::class,
|
||||
LoginFailedException::class,
|
||||
ValidateException::class,
|
||||
PermissionForbiddenException::class,
|
||||
];
|
||||
/**
|
||||
* 记录异常信息(包括日志或者其它方式记录)
|
||||
*
|
||||
@@ -45,16 +54,17 @@ class ExceptionHandle extends Handle
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @access public
|
||||
* @param \think\Request $request
|
||||
* @param \think\Request $request
|
||||
* @param Throwable $e
|
||||
* @return Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function render($request, Throwable $e): Response
|
||||
{
|
||||
// 添加自定义异常处理机制
|
||||
if ($request->isAjax()) {
|
||||
if (in_array(get_class($e), $this->catchExceptions)) {
|
||||
return CatchResponse::fail($e->getMessage(), $e->getCode());
|
||||
}
|
||||
|
||||
// 其他错误交给系统处理
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
|
Reference in New Issue
Block a user