예제 #1
0
 public static function handler(Exception $e)
 {
     if (Kohana::$environment !== Kohana::PRODUCTION) {
         parent::handler($e);
     } else {
         try {
             //not saving 404 as error
             if ($e->getCode() != 404) {
                 Kohana::$log->add(Log::ERROR, parent::text($e));
             }
             $params = array('action' => 500, 'origuri' => rawurlencode(Arr::get($_SERVER, 'REQUEST_URI')), 'message' => rawurlencode($e->getMessage()));
             if ($e instanceof HTTP_Exception) {
                 $params['action'] = $e->getCode();
             }
             //d($params);
             // Error sub-request.
             echo Request::factory(Route::get('error')->uri($params))->execute()->send_headers()->body();
         } 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(1);
         }
     }
 }
예제 #2
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;
     }
 }
예제 #3
0
 public static function handlers(Exception $e)
 {
     die;
     if (stripos(get_class($e), 'Smarty')) {
         echo 'Smarty Found';
     }
     if (Kohana::DEVELOPMENT === Kohana::$environment) {
         parent::handler($e);
     } else {
         try {
             Kohana::$log->add(Log::ERROR, parent::text($e));
             $attributes = array('code' => 500, 'e' => rawurlencode($e->getMessage()));
             if ($e instanceof HTTP_Exception) {
                 $attributes['code'] = $e->getCode();
             }
             // Error sub-request.
             echo Request::factory(Route::get('error')->uri($attributes))->execute()->send_headers()->body();
         } 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(1);
         }
     }
 }
 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;
 }
예제 #5
0
 public static function handler($e)
 {
     Raven::instance()->captureException($e);
     //Kohana handler adds a Log::ERROR string to log, so double-sending would be undesired
     Kohana::$log->detach(Log_Raven::instance());
     parent::handler($e);
     //there's death call
 }
예제 #6
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;
     }
 }
예제 #7
0
 public static function handler(Exception $e)
 {
     if (Kohana::$environment == Kohana::DEVELOPMENT) {
         return parent::handler($e);
     }
     try {
         $params = array('action' => rawurlencode('thrown'), 'code' => base64_encode($e instanceof HTTP_Exception ? $e->getCode() : 500), 'message' => base64_encode($e->getMessage()));
         die(Request::factory(Route::get('exception')->uri($params))->execute()->send_headers()->body());
     } catch (Exception $e2) {
         ob_clean();
         die("A fatal error has occurred: " . parent::text($e2));
     }
 }
예제 #8
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;
     }
 }
예제 #9
0
파일: exception.php 프로젝트: kanikaN/qload
 /**
  * Overriden to show custom page for 404 errors
  */
 public static function handler(Exception $e)
 {
     switch (get_class($e)) {
         case 'HTTP_Exception_404':
             $response = new Response();
             $response->status(404);
             //  $view = new View('errors/report');
             // $view->message = $e->getMessage();
             echo $response->body("<h2>Page Not Found</h2> <a href=\"/\" >Go Home</a>")->send_headers()->body();
             return TRUE;
             break;
         default:
             return Kohana_Kohana_Exception::handler($e);
             break;
     }
 }
예제 #10
0
파일: Exception.php 프로젝트: g-a-g/its2015
 protected static function _show_error($error, $attributes, $route = 'error')
 {
     // Логируем ошибку
     Kohana::$log->add(Log::ERROR, parent::text($error))->write();
     try {
         echo Request::factory(Route::url($route, $attributes))->execute()->send_headers()->body();
     } catch (Exception $e) {
         // Clean the output buffer if one exists
         ob_get_level() and ob_clean();
         // Display the exception text
         echo parent::text($e);
         // Log error
         Kohana::$log->add(Log::ERROR, parent::text($e))->write();
         // Exit with an error status
         exit(1);
     }
 }
예제 #11
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);
     }
 }
예제 #12
0
 /**
  * Inline exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  *
  * @uses    Kohana_Exception::text
  * @param   object   exception object
  * @return  boolean
  */
 public static function handler(Exception $e)
 {
     if (Kohana::DEVELOPMENT === Kohana::$environment or Kohana::$is_cli) {
         return parent::handler($e);
     } else {
         try {
             Kohana::$log->add(Log::ERROR, parent::text($e));
             $attributes = array('action' => 500, 'message' => rawurlencode($e->getMessage()));
             // чтобы для админки вызывался свой контроллер ошибок
             $route_name = 'error';
             $route = Request::initial()->route();
             if ($route) {
                 $reserved_routes = Kohana::$config->load('admin/site.reserved_routes');
                 if (in_array($route->route_name, $reserved_routes)) {
                     $route_name = 'admin_error';
                 }
             }
             if ($e instanceof HTTP_Exception) {
                 $attributes['action'] = $e->getCode();
             }
             // Clean the output buffer
             ob_get_level() and ob_clean();
             // Start an output buffer
             ob_start();
             // Error sub-request.
             echo Request::factory(Route::get($route_name)->uri($attributes))->execute()->send_headers()->body();
             // Display the contents of the output buffer
             echo ob_get_clean();
             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(1);
         }
     }
 }
예제 #13
0
 public static function handler(Exception $e)
 {
     // Стандартная обработка, если проект на стадии разработки
     if (Kohana::DEVELOPMENT === Kohana::$environment) {
         parent::handler($e);
     } else {
         try {
             // Пишем в лог
             Kohana::$log->add(Log::ERROR, parent::text($e));
             $attributes = array('action' => 500, 'message' => rawurlencode($e->getMessage()));
             // Получаем код ошибки, как название экшена
             if ($e instanceof HTTP_Exception) {
                 $attributes['action'] = $e->getCode();
             }
             // Выполняем запрос, обращаясь к роутеру для обработки ошибок
             echo Request::factory(Route::get('error')->uri($attributes))->execute()->send_headers()->body();
         } catch (Exception $e) {
             // Чистим буфер и выводим текст ошибки
             ob_get_level() and ob_clean();
             echo parent::text($e);
             exit(1);
         }
     }
 }
예제 #14
0
파일: exception.php 프로젝트: anqh/anqh
 /**
  * Exception handler.
  *
  * @static
  * @param   Exception $e
  * @return  boolean
  */
 public static function handler(Exception $e)
 {
     // Development environment shows all exceptions
     if (Kohana::$environment === Kohana::DEVELOPMENT) {
         return parent::handler($e);
     }
     try {
         // Log errors
         Kohana::$log->add(Log::ERROR, self::text($e));
         // Figure out error page attributes
         $params = array('action' => 500, 'message' => rawurlencode($e->getMessage()));
         if ($e instanceof HTTP_Exception) {
             // Different errors pages for different HTTP errors
             $params['action'] = $e->getCode();
         } else {
             if ($e instanceof ReflectionException) {
                 // This really shouldn't happen, ever
                 $params['action'] = 404;
             } else {
                 if ($e instanceof Controller_API_Exception) {
                     // API error
                     $params['action'] = 403;
                 }
             }
         }
         // Display error page
         echo Request::factory(Route::url('error', $params))->execute()->send_headers()->body();
     } catch (Exception $e) {
         // Clean buffers
         ob_get_level() and ob_clean();
         // Display exception
         echo parent::text($e);
         // Exit with error
         exit(1);
     }
 }
예제 #15
0
 public static function response(Exception $e)
 {
     $response = parent::response($e);
     self::static_add_cors_headers($response);
     return $response;
 }
예제 #16
0
 /**
  * Inline exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  *
  * @uses    Kohana_Exception::text
  * @param   object   exception object
  * @return  boolean
  */
 public static function handler(Exception $e)
 {
     if (Kohana::DEVELOPMENT === Kohana::$environment or Kohana::$is_cli) {
         return parent::handler($e);
     }
     try {
         // Get the exception information
         $type = get_class($e);
         $code = $e->getCode();
         $message = strip_tags($e->getMessage());
         $file = Debug::path($e->getFile());
         $line = $e->getLine();
         if ($e instanceof ErrorException) {
             if (isset(Kohana_Exception::$php_errors[$code])) {
                 // Use the human-readable error name
                 $code = Kohana_Exception::$php_errors[$code];
             }
         }
         // Create a text version of the exception
         $error = "{$type} [{$code}]: {$message} ~ {$file} [{$line}]";
         if (is_object(Kohana::$log)) {
             // Add this exception to the log
             Kohana::$log->add(Log::ERROR, $error);
             // Make sure the logs are written
             Kohana::$log->write();
         }
         // Clean the output buffer
         ob_get_level() and ob_clean();
         // Make sure the proper http header is sent
         $http_header_status = $e instanceof HTTP_Exception ? $e->getCode() : 500;
         // Make correct title
         $title = isset(Response::$messages[$http_header_status]) ? Response::$messages[$http_header_status] : $type;
         if (!headers_sent()) {
             header('Content-Type: ' . Kohana_Exception::$error_view_content_type . '; charset=' . Kohana::$charset, TRUE, $http_header_status);
         }
         if (Request::$current !== NULL and Request::current()->is_ajax() === TRUE) {
             // Just display the text of the exception
             echo "\n{$type} [{$code}]: {$message}\n";
             // Exit with an error status
             exit(1);
         } else {
             // Start an output buffer
             ob_start();
             // Include the exception HTML
             if ($view_file = Kohana::find_file('views', Kohana_Exception::$frontend_error_view . '/' . $http_header_status)) {
                 // Include custom exception view
                 include $view_file;
             }
             if ($view_file = Kohana::find_file('views', Kohana_Exception::$frontend_error_view)) {
                 // Include common exception view
                 include $view_file;
             } else {
                 throw new Kohana_Exception('Error view file does not exist: views/:file', array(':file' => Kohana_Exception::$frontend_error_view));
             }
             // Display the contents of the output buffer
             echo ob_get_clean();
             // Exit with an error status
             exit(1);
         }
     } 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(1);
     }
 }