Example #1
0
 public function indexAction()
 {
     switch ($this->error->type()) {
         case 404:
             $this->tag->setTitle('Page not found');
             $code = 404;
             $message = 'Unfortunately, the page you are requesting can not be found!';
             break;
         case 403:
             $this->tag->setTitle('Access is denied');
             $code = 403;
             $message = 'Access to this resource is denied by the administrator.';
             break;
         case 401:
             $this->tag->setTitle('Authorization required');
             $code = 401;
             $message = 'To access the requested resource requires authentication.';
             break;
         default:
             $this->tag->setTitle('Something is not quite right');
             $code = 500;
             $message = 'Unfortunately an unexpected system error occurred.';
     }
     $this->response->resetHeaders()->setStatusCode($code, null);
     $this->view->setVars(['code' => $code, 'message' => $message]);
 }
Example #2
0
 /**
  * Logs the error and dispatches an error controller.
  *
  * @param  \Phalcon\Error\Error $error
  * @return mixed
  */
 public static function handle(Error $error)
 {
     $di = Di::getDefault();
     $config = $di->getShared('config')->error;
     $type = static::getErrorType($error->type());
     $message = "{$type}: {$error->message()} in {$error->file()} on line {$error->line()}";
     if (isset($config->formatter) && $config->formatter instanceof Formatter) {
         $config->logger->setFormatter($config->formatter);
     }
     $config->logger->log($message);
     switch ($error->type()) {
         case E_WARNING:
         case E_NOTICE:
         case E_CORE_WARNING:
         case E_COMPILE_WARNING:
         case E_USER_WARNING:
         case E_USER_NOTICE:
         case E_STRICT:
         case E_DEPRECATED:
         case E_USER_DEPRECATED:
         case E_ALL:
             break;
         case 0:
         case E_ERROR:
         case E_PARSE:
         case E_CORE_ERROR:
         case E_COMPILE_ERROR:
         case E_USER_ERROR:
         case E_RECOVERABLE_ERROR:
             $dispatcher = $di->getShared('dispatcher');
             $view = $di->getShared('view');
             $response = $di->getShared('response');
             $dispatcher->setControllerName($config->controller);
             $dispatcher->setActionName($config->action);
             $dispatcher->setParams(['error' => $error]);
             $view->start();
             $dispatcher->dispatch();
             $view->render($config->controller, $config->action, $dispatcher->getParams());
             $view->finish();
             return $response->setContent($view->getContent())->send();
     }
 }
Example #3
0
 /**
  * Logs the error and dispatches an error controller.
  *
  * @param  \Phalcon\Error\Error $error
  * @return mixed
  */
 public static function handle(Error $error)
 {
     $di = Di::getDefault();
     $config = $di->getShared('config')->error->toArray();
     $logger = $config['logger'];
     if (!$logger instanceof AdapterInterface) {
         $logger = new FileLogger($logger);
     }
     $type = static::getErrorType($error->type());
     $message = "{$type}: {$error->message()} in {$error->file()} on line {$error->line()}";
     if (isset($config['formatter'])) {
         $formatter = null;
         if ($config['formatter'] instanceof Formatter) {
             $formatter = $config['formatter'];
         } elseif (is_array($config['formatter'])) {
             $format = null;
             $dateFormat = null;
             if (isset($config['formatter']['format'])) {
                 $format = $config['formatter']['format'];
             }
             if (isset($config['formatter']['dateFormat'])) {
                 $dateFormat = $config['formatter']['dateFormat'];
             } elseif (isset($config['formatter']['date_format'])) {
                 $dateFormat = $config['formatter']['date_format'];
             } elseif (isset($config['formatter']['date'])) {
                 $dateFormat = $config['formatter']['date'];
             }
             $formatter = new FormatterLine($format, $dateFormat);
         }
         if ($formatter) {
             $logger->setFormatter($formatter);
         }
     }
     $logger->log(static::getLogType($error->type()), $message);
     switch ($error->type()) {
         case E_WARNING:
         case E_NOTICE:
         case E_CORE_WARNING:
         case E_COMPILE_WARNING:
         case E_USER_WARNING:
         case E_USER_NOTICE:
         case E_STRICT:
         case E_DEPRECATED:
         case E_USER_DEPRECATED:
         case E_ALL:
             break;
         case 0:
         case E_ERROR:
         case E_PARSE:
         case E_CORE_ERROR:
         case E_COMPILE_ERROR:
         case E_USER_ERROR:
         case E_RECOVERABLE_ERROR:
             if ($di->has('view')) {
                 $dispatcher = $di->getShared('dispatcher');
                 $view = $di->getShared('view');
                 $response = $di->getShared('response');
                 $dispatcher->setControllerName($config['controller']);
                 $dispatcher->setActionName($config['action']);
                 $dispatcher->setParams(['error' => $error]);
                 $view->start();
                 $dispatcher->dispatch();
                 $view->render($config['controller'], $config['action'], $dispatcher->getParams());
                 $view->finish();
                 return $response->setContent($view->getContent())->send();
             } else {
                 echo $message;
             }
     }
 }