Example #1
0
 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');
     }
 }