isIgnoreReport($exception)) { $data = [ 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'message' => $this->getMessage($exception), 'code' => $this->getCode($exception), ]; response_log_write($data); } } /** * 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 { // 添加自定义异常处理机制 $massageData = Env::get('app_debug', false) ? [ 'file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => $e->getTrace(), 'previous' => $e->getPrevious(), ] : []; // 添加自定义异常处理机制 if ($e instanceof DbException) { return app('json')->fail('数据获取失败:' . $e->getMessage(), $massageData); } elseif ($e instanceof AuthException || $e instanceof ValidateException || $e instanceof ApiException || $e instanceof PayException || $e instanceof TemplateException || $e instanceof UploadException || $e instanceof WechatReplyException || $e instanceof AdminException || $e instanceof WechatException ) { return app('json')->make($e->getCode() ?: 400, $e->getMessage(), $massageData); } else { return app('json')->code(500)->make(400, $e->getMessage(), $massageData); } } }