Beispiel #1
0
 /**
  * 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);
 }
 public function processError($request, $exception)
 {
     $response = new Response();
     $viewVars = ["exception" => $exception];
     $code = 500;
     $errorCode = $exception->getCode();
     if ($errorCode >= 400 && $errorCode < 506) {
         $code = $errorCode;
     }
     $response->statusCode($code);
     $viewVars["code"] = $code;
     if (method_exists($exception, 'responseHeader')) {
         $response->header($exception->responseHeader());
     }
     if ($request) {
         $viewVars["url"] = $request->url();
     }
     $isDebug = Configuration::getInstance()->get("debug");
     if ($isDebug) {
         $viewVars['trace'] = Debugger::formatTrace($exception->getTrace(), ['format' => 'array', 'args' => false]);
     }
     $message = $exception->getMessage();
     $isHttpException = $exception instanceof HttpException;
     if (!$isDebug && !$isHttpException) {
         if ($code < 500) {
             $message = \CoreTyson\tr('cake', 'Not Found');
         } else {
             $message = \CoreTyson\tr('cake', 'An Internal Error Has Occurred.');
         }
     }
     $viewVars["message"] = $message;
     $template = "error" . $code;
     if (!$isDebug && !$isHttpException) {
         $template = 'error500';
         if ($code < 500) {
             $template = 'error400';
         }
     }
     if ($isHttpException) {
         $template = 'error500';
         if ($code < 500) {
             $template = 'error400';
         }
     }
     if ($exception instanceof PDOException) {
         $template = 'pdo_error';
     }
     try {
         $view = new View();
         $response->body($view->render("Error/" . $template));
     } catch (MissingTemplateException $e) {
         return $this->_outputMessageSafe('error500');
     } catch (MissingPluginException $e) {
         $attributes = $e->getAttributes();
         if (isset($attributes['plugin']) && $attributes['plugin'] === $this->controller->plugin) {
             $this->controller->plugin = null;
         }
         return $this->_outputMessageSafe('error500');
     } catch (Exception $e) {
         return $this->_outputMessageSafe('error500');
     }
 }