/**
  * Attempt to query error/500 manually, as we cannot catch exceptions through traditional HMVC requests.
  * Catch potential exceptions such as database is down and display a lightweight error message.
  *
  * @param Exception $e
  * @return Response
  */
 public static function response(Exception $e)
 {
     if (Kohana::$environment >= Kohana::DEVELOPMENT) {
         return parent::response($e);
     }
     try {
         // Create the request, we need to set controller and action manual as they
         // otherwise gets set in execute method.
         $request = Request::factory();
         $request->controller(Kohana_Exception::$_controller);
         $request->action(Kohana_Exception::$_method);
         // Setup the response object
         $response = Response::factory();
         $response->status(500);
         $response->headers('Content-Type', Kohana_Exception::$error_view_content_type . '; charset=' . Kohana::$charset);
         // Call the controller.
         $controller = new Controller_Error($request, $response);
         return $controller->execute();
     } catch (Exception $e) {
         // Render the fallback view.
         $view = View::factory('errors/fallback');
         $response = Response::factory();
         $response->status(500);
         $response->body($view->render());
         return $response;
     }
 }
Exemple #2
0
 /**
  * Método para manejar las excepciones ocurridas en la aplicación
  * @param exception Excepción producida (\Exception  o \Error)
  * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]delaf.cl)
  * @version 2016-01-07
  */
 public static function handler($exception)
 {
     ob_clean();
     // Generar arreglo
     $data = array('exception' => get_class($exception), 'message' => $exception->getMessage(), 'trace' => $exception->getTraceAsString(), 'code' => $exception->getCode(), 'severity' => isset($exception->severity) ? $exception->severity : LOG_ERR);
     // renderizar dependiendo de si es una web o es una shell
     if (isset($_SERVER['REQUEST_URI'])) {
         $controller = new Controller_Error(new Network_Request(), new Network_Response());
         $controller->error_reporting = Configure::read('debug');
         $controller->display($data);
         $controller->shutdownProcess();
         $controller->response->status($data['code']);
         $controller->response->send();
     } else {
         $stdout = new Shell_Output('php://stdout');
         $stdout->write("\n" . '<error>' . $data['exception'] . ':</error>', 2);
         $stdout->write("\t" . '<error>' . str_replace("\n", "\n\t", $data['message']) . '</error>', 2);
         $stdout->write("\t" . '<error>' . str_replace("\n", "\n\t", $data['trace']) . '</error>', 2);
     }
 }