TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
Hiding errors
  • Hi,

    How can I disable displaying these red kohana errors and backtraces? And eventually customize my own error pages.
  • There's some info about catching errors etc in the installation page of official guide, under the section Setting up a Production Environment.

    You can also find some extra info in the docs here: http://michaeldpeters.com/docs.kohanaphp.com/3.0/kohana/concepts/bootstrap

    The unofficial wiki by kerkness is also a really useful source of info.
  • Thanks. I disabled kohana errors, so it's a bit better now. But uncaught exceptions are still displayed. I've tried in APP/bootstrap this:

    Route::set('catch_all', '', array('path' => '.+'))
    ->defaults(array(
    'controller' => 'errors',
    'action' => '404'
    ));

    And this:

    $request = Request::instance();

    try
    {
    // Execute the main request
    $request->execute();
    }
    catch (Exception $e)
    {
    // Be sure to log the error
    Kohana::$log->add(Kohana::ERROR, Kohana::exception_text($e));

    // If there was an error, send a 404 response and display an error
    $request->status = 404;
    $request->response = View::factory('errors/404');
    }

    // Send the headers and echo the response
    $request->send_headers();
    echo $request->response;

    None worked. Am I supposed to add something else? (I've created proper controllers and view file).
  • Route::set('error', 'errors/404');

    $request = Request::instance();
    try
    {
    $request->execute();
    }
    catch( ReflectionException $e )
    {
    $new_request = Request::factory('errors/404');

    $new_request->execute();
    $new_request->status = 404;
    if ( $new_request->send_headers() )
    {
    die( $new_request->response );
    }
    }
    if ( $request->send_headers()->response )
    {
    echo $request->response;
    }

    It doesn't catch errors, what is wrong?
  • Your error could be in the Request::instance() since it is not being included in the try block. You are also only catching instances of ReflectionException. If you want to catch all errors you should just catch(Exception $e). Also you need to be certain that the Request::factory('errors/404') does not throw any errors because if it does they won't be cautght.
  • Yes, thank you, it's working now.