first commit
This commit is contained in:
18
pgserver/application/admin/exception/Handler.php
Normal file
18
pgserver/application/admin/exception/Handler.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\admin\exception;
|
||||
|
||||
use think\exception\Handle;
|
||||
|
||||
class Handler extends Handle
|
||||
{
|
||||
public function convertExceptionToResponse(\Exception $exception)
|
||||
{
|
||||
if ($exception instanceof RenderException){
|
||||
return $exception->render();
|
||||
}else{
|
||||
return parent::convertExceptionToResponse($exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
pgserver/application/admin/exception/LogicException.php
Normal file
31
pgserver/application/admin/exception/LogicException.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\admin\exception;
|
||||
|
||||
|
||||
use think\Container;
|
||||
use think\Response;
|
||||
|
||||
class LogicException extends \Exception implements RenderException
|
||||
{
|
||||
|
||||
public $errors;
|
||||
|
||||
public function __construct($msg = '',$code = 500,$errors = [])
|
||||
{
|
||||
parent::__construct($msg,$code);
|
||||
$this->errors = $errors;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$data['code'] = $this->getCode();
|
||||
$data['msg'] = $this->getMessage();
|
||||
$data['data'] = $this->errors;
|
||||
if (Container::get('app')->isDebug()){
|
||||
$data['trace'] = $this->getTrace();
|
||||
}
|
||||
return Response::create($data,'json');
|
||||
}
|
||||
}
|
||||
10
pgserver/application/admin/exception/RenderException.php
Normal file
10
pgserver/application/admin/exception/RenderException.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\admin\exception;
|
||||
|
||||
|
||||
interface RenderException
|
||||
{
|
||||
public function render();
|
||||
}
|
||||
Reference in New Issue
Block a user