### 1.创建BaseException
~~~
namespace app\common\controller;
use Exception;
use think\exception\Handle;
class BaseException extends Handle
{
public function render(Exception $e)
{
return $this->show(1, $e->getMessage(), [], $this->httpCode);
}
public function show($code, $msg ,$data = [] ,$httpCode = 200)
{
$data = [
'code' => $code,
'msg' => $msg,
'data' =>$data
];
return json($data, $httpCode);
}
}
~~~
### 2.修改config/app.php
~~~
'exception_handle' => '\app\common\controller\ApiException',
~~~