protected function _outputMessage($template) { $error = $this->controller->viewVars['error']; $data = []; $data['class'] = 'Error'; $data['code'] = $error->getCode(); $data['url'] = '/' . $this->controller->request->url; $data['message'] = $error->getMessage(); $data['errors'] = $this->controller->viewVars['errors']; if (Configure::read('debug')) { $data['DEBUG']['trace'] = Debugger::formatTrace($error->getTrace(), ['format' => 'array', 'args' => false]); $queryLog = $this->_getQueryLog(); if ($queryLog) { $data['DEBUG']['queryLog'] = $queryLog; } } $jsonOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT; if (Configure::read('debug')) { $jsonOptions = $jsonOptions | JSON_PRETTY_PRINT; } $this->controller->response->type('json'); $this->controller->response->body(json_encode($data, $jsonOptions)); $this->controller->response->statusCode($data['code']); return $this->controller->response; }
/** * Helper method used to generate extra debugging data into the error template * * @return array debugging data */ protected function _getErrorData() { $data = []; $viewVars = $this->controller->viewVars; if (!empty($viewVars['_serialize'])) { foreach ($viewVars['_serialize'] as $v) { $data[$v] = $viewVars[$v]; } } if (!empty($viewVars['error']) && Configure::read('debug')) { $data['exception'] = ['class' => get_class($viewVars['error']), 'code' => $viewVars['error']->getCode(), 'message' => $viewVars['error']->getMessage()]; if (!isset($data['trace'])) { $data['trace'] = Debugger::formatTrace($viewVars['error']->getTrace(), ['format' => 'array', 'args' => false]); } } return $data; }
/** * Renders the response for the exception. * * @return \Cake\Network\Response The response to be sent. */ public function render() { $exception = $this->error; $code = $this->_code($exception); $method = $this->_method($exception); $template = $this->_template($exception, $method, $code); $unwrapped = $this->_unwrap($exception); $isDebug = Configure::read('debug'); if (($isDebug || $exception instanceof HttpException) && method_exists($this, $method)) { return $this->_customMethod($method, $unwrapped); } $message = $this->_message($exception, $code); $url = $this->controller->request->here(); if (method_exists($exception, 'responseHeader')) { $this->controller->response->header($exception->responseHeader()); } $this->controller->response->statusCode($code); $viewVars = ['message' => $message, 'url' => h($url), 'error' => $unwrapped, 'code' => $code, '_serialize' => ['message', 'url', 'code']]; if ($isDebug) { $viewVars['trace'] = Debugger::formatTrace($unwrapped->getTrace(), ['format' => 'array', 'args' => false]); $viewVars['_serialize'][] = 'trace'; } $this->controller->set($viewVars); if ($unwrapped instanceof CakeException && $isDebug) { $this->controller->set($unwrapped->getAttributes()); } return $this->_outputMessage($template); }
/** * Outputs a stack trace based on the supplied options. * * ### Options * * - `depth` - The number of stack frames to return. Defaults to 999 * - `format` - The format you want the return. Defaults to the currently selected format. If * format is 'array' or 'points' the return will be an array. * - `args` - Should arguments for functions be shown? If true, the arguments for each method call * will be displayed. * - `start` - The stack frame to start generating a trace from. Defaults to 0 * * @param array $options Format for outputting stack trace. * @return mixed Formatted stack trace. * @link http://book.cakephp.org/3.0/en/development/debugging.html#generating-stack-traces */ public static function trace(array $options = []) { return Debugger::formatTrace(debug_backtrace(), $options); }