/** * Render an exception into an HTTP response. * * @access public * @param \think\Request $request * @param Throwable $e * @return Response */ public function render($request, Throwable $e): Response { // app_debug模式下按原thinkphp6异常模式处理异常 if (env('app_debug')) { return parent::render($request, $e); } // 获取当前访问应用 $app_name = app('http')->getName(); switch ($app_name) { case 'admin': // 自定义json返回错误 if ($e instanceof ValidateException) { // return json($e->getError(), 422); return json(['code' => 0, 'msg' => $e->getError()], 422); } // 自定义json返回异常 if ($e instanceof HttpException && $request->isAjax()) { return json(['code' => 0, 'msg' => $e->getMessage()], $e->getStatusCode()); } // 自定义json返回异常 if ($e instanceof HttpException) { return json(['code' => 0, 'msg' => $e->getMessage()]); } // 自定义json返回异常 $errorData = [ 'code' => 0, 'msg' => $e->getMessage(), 'errorcode' => $e->getCode(), 'result' => '未知错误,请开启调试模式。Unknown error, please turn on debugging mode' ]; return json($errorData); break; default: return parent::render($request, $e); break; } }
上一篇: 《建站管家》二次开发文档
下一篇: git push失败,提示fatal: The current branch master has no upstream branch的解决办法