## 1. 内部异常捕获 切换到你的**应用根目录/app/common**, 新增exception文件夹,新建Http.php ~~~ class Http extends Handle { public function render($request, Throwable $e): Response { // 请求异常 if ($request->isAjax()) { show(10001,$e->getMessage(),[],500); }else{ exit($e->getMessage()); } } } ~~~ ## 2. 配置异常拦截 切换到你的**应用根目录/app/应用目录**, 新建Provider.php ~~~ return [ 'think\exception\Handle' => '\\app\\common\\exception\\Http', ]; ~~~ ## 3. 效果演示: ![](https://img.kancloud.cn/d3/e7/d3e75491990a121faf684389dd6538be_650x273.png) ![](https://img.kancloud.cn/c1/ff/c1ff47bb9e684648269fbb8115ec8c92_1079x191.png)