예제 #1
0
 /**
  * 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;
     }
 }
 public static function response(Exception $e)
 {
     // get the response
     $response = parent::response($e);
     //  Log the Exception,
     Kohana_Exception::log($e);
     if (Kohana::DEVELOPMENT !== Kohana::$environment) {
         try {
             // fire error subrequest
             // directly output result
             echo Request::factory(Route::get('error')->uri(array('controller' => 'error', 'action' => 'view')))->post('exception', $e)->execute()->send_headers()->body();
             exit;
         } catch (Exception $e) {
             // Clean the output buffer if one exists
             ob_get_level() and ob_clean();
             // Display the exception text
             echo parent::text($e);
             // Exit with an error status
             exit;
         }
     }
     // end all output buffering
     $ob = ob_get_level();
     for ($i = 0; $i < $ob; $i++) {
         ob_end_clean();
     }
     // return the response as usual
     return $response;
 }
예제 #3
0
 public static function response(Exception $e)
 {
     // handle error
     if (Kohana::$environment >= Kohana::DEVELOPMENT) {
         return parent::response($e);
     } else {
         $view = new View('templates/errors/default');
         $view->set('title', "500 Internal Server Error");
         $view->set('message', "{$e->getMessage()}");
         $response = Response::factory()->status(500)->body($view->render());
         return $response;
     }
 }
예제 #4
0
 /**
  * Get a Response object representing the exception
  *
  * @uses    Kohana_Exception::text
  * @param   Exception  $e
  * @return  Response
  */
 public static function response($e)
 {
     if (Kohana::$environment === Kohana::DEVELOPMENT) {
         // Show the normal Kohana error page.
         return parent::response($e);
     } else {
         // Lets log the Exception, Just in case it's important!
         Kohana::$log->add(Log::ERROR, parent::text($e));
         // Generate a nicer looking "Oops" page.
         $view = View::factory('pages/error/default', array('message' => $e->getMessage()));
         $response = Response::factory()->status(500)->body($view->render());
         return $response;
     }
 }
예제 #5
0
 protected static function _show_custom_error($e)
 {
     $params = array('code' => 500, 'message' => rawurlencode($e->getMessage()));
     if ($e instanceof HTTP_Exception) {
         $params['code'] = $e->getCode();
     }
     try {
         $request = Request::factory(Route::get('error')->uri($params), array(), FALSE)->execute()->send_headers(TRUE)->body();
         // Prepare the response object.
         $response = Response::factory();
         // Set the response status
         $response->status($e instanceof HTTP_Exception ? $e->getCode() : 500);
         // Set the response body
         $response->body($request);
         return $response;
     } catch (Exception $e) {
         return parent::response($e);
     }
 }
예제 #6
0
파일: Exception.php 프로젝트: g-a-g/its2015
 public static function response(Exception $e)
 {
     //        if (Kohana::$environment >= Kohana::DEVELOPMENT  OR PHP_SAPI == 'cli')
     //        {
     //            // Show the normal Kohana error page.
     //            return parent::response();
     //        }
     // Если AJAX запрос, перенаправляем его на Controller_AJAX_Error
     if (Request::initial() !== NULL and Request::initial()->is_ajax()) {
         $attributes = array('directory' => 'ajax', 'controller' => 'error', 'action' => 'index', 'id' => rawurlencode($e->getMessage()));
         self::_show_error($e, $attributes, 'system');
     } elseif (Kohana::$environment >= Kohana::DEVELOPMENT or PHP_SAPI == 'cli') {
         return parent::response($e);
     } else {
         $attributes = array('message' => rawurlencode($e->getMessage()));
         self::_show_error($e, $attributes);
     }
     $response = Response::factory();
     return $response;
 }
예제 #7
0
 public static function response(Exception $e)
 {
     $response = parent::response($e);
     self::static_add_cors_headers($response);
     return $response;
 }