code = $e->code; $this->message = $e->message; } else { if (config('app_debug')) { return parent::render($e); } $this->code = 0; $this->message = $e->getMessage() ?: '很抱歉,服务器内部错误'; $this->recordErrorLog($e); } return json(['msg' => $this->message, 'code' => $this->code]); } /** * 将异常写入日志 * @param Exception $e */ private function recordErrorLog(Exception $e) { Log::record($e->getMessage(), 'error'); Log::record($e->getTraceAsString(), 'error'); } }