app->isDebug()) { // 调试模式,获取详细的错误信息 $traces = []; $nextException = $exception; do { $traces[] = [ 'name' => $nextException::class, 'file' => $nextException->getFile(), 'line' => $nextException->getLine(), 'code' => $this->getCode($nextException), 'message' => $this->getMessage($nextException), 'trace' => $nextException->getTrace(), 'source' => $this->getSourceCode($nextException), ]; } while ($nextException = $nextException->getPrevious()); // 循环引用检测并直接置空 traces(比起循环引用导致的报错,置空后开发者能得到更多真实的错误信息) if ($this->app->request->isJson()) { $json = json_encode($traces, JSON_UNESCAPED_UNICODE); if (false === $json && in_array(json_last_error(), [JSON_ERROR_DEPTH, JSON_ERROR_RECURSION])) { $traces = []; } } $data = [ 'code' => $this->getCode($exception), 'message' => $this->getMessage($exception), 'traces' => $traces, 'datas' => $this->getExtendData($exception), 'tables' => [ 'GET Data' => $this->app->request->get(), 'POST Data' => $this->app->request->post(), 'Files' => $this->app->request->file(), 'Cookies' => $this->app->request->cookie(), 'Session' => $this->app->exists('session') ? $this->app->session->all() : [], 'Server/Request Data' => $this->app->request->server(), ], ]; } else { // 部署模式仅显示 Code 和 Message $data = [ 'code' => $this->getCode($exception), 'message' => $this->getMessage($exception), ]; if (!$this->app->config->get('app.show_error_msg')) { // 不显示详细错误信息 $data['message'] = $this->app->config->get('app.error_message'); } } return $data; } }