Welcome Guest, Not a member yet? Register   Sign In
Production environment: error page for fatal errors
#1

[eluser]Unknown[/eluser]
Hi guys,

Do any of you know if there is a possibility to show a nice error page when a fatal error occurs? When you set the environment variable in index.php to 'production' the page just stays white, and I think it is convenient to show a page with some description.

Of course I could modify the default CodeIgniter code, but I would like to avoid that, so I am hoping one of you could help me out with some idea's.
#2

[eluser]CroNiX[/eluser]
You'd probably have to create a MY_Exceptions to create that functionality. But, there shouldn't be any fatal errors on a production box. That would indicate a bug that needs fixing.
#3

[eluser]Unknown[/eluser]
Of course those needs fixing, but if there may occur a fatal error, for example, when a file is missing, it would be nice if there was something more than just a blank page, in general users do not know what to do with a blank screen.

So besides extending the core class there is no way this could be implemented? Well, it is way better than nothing. Thank you for your response.
#4

[eluser]skunkbad[/eluser]
You could create a custom error handler in a hook, using set_error_handler. I use one that emails me the error info.

Code:
<?php
function my_error_handling(){
function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) {
  $message = "An error #" . $e_number . " occurred in script '$e_file' on line $e_line: \n<br />$e_message\n<br />";
  $message .= "Date/Time: " . date('n-j-Y H:i:s') . "\n<br />";
  $message .= "<pre>" . print_r ($e_vars, 1) . "</pre>\n<br />";
  if ( ENVIRONMENT == 'development') {
   echo '<p class="error">' . $message . '</p>';
  }else{
   error_log ($message, 1, ADMIN_EMAIL_ADDRESS );
   if ( ($e_number != E_NOTICE) && ($e_number < 2048)) {
    echo '<p class="error">A system error occurred. We apologize for the inconvenience.</p>';
   }
  }
}
set_error_handler ('my_error_handler',E_ALL^E_NOTICE);
}
/* End of file my_error_handling_hook.php */
/* Location: /application/hooks/my_error_handling_hook.php */

You could easily customize this to display whatever you want to the site visitor.




Theme © iAndrew 2016 - Forum software by © MyBB