R
R
ragnar_ok2019-09-03 15:14:41
1C-Bitrix
ragnar_ok, 2019-09-03 15:14:41

How to redirect to the 500.php page?

How do I redirect to the 500.php page so that the .htaccess ErrorDocument 500 /500.php rule will work ?
The code below works without including the header:

<?php
ini_set('display_errors', 0);
throw new Error('Error!');

But as soon as I request header , it displays a stack trace (or " An error occurred while executing the script. You can enable extended error output in the .settings.php configuration file " if debug is disabled).
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");

Contents of the exception_handling .settings.php file :
'exception_handling' =>
  array (
    'value' =>
    array (
      'debug' => false,
      'handled_errors_types' => 4437,
      'exception_errors_types' => 4437,
      'ignore_silence' => false,
      'assertion_throws_exception' => true,
      'assertion_error_type' => 256,
      'log' => NULL,
    ),
    'readonly' => false,
  ),

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
ragnar_ok, 2019-09-04
@ragnar_ok

With a friend found that in Bitrix\Main\Diag\ExceptionHandleris called set_exception_handler(function () {}).
Starting from ExceptionHandler in init.php indicated the following:

if (!Bitrix\Main\Config\Configuration::getValue('exception_handling')['debug']) { // если 'exception_handling' => ['value' => ['debug' => false]]
    set_exception_handler(function ($exception) {
        (new Bitrix\Main\Diag\ExceptionHandler())->writeToLog($exception, Bitrix\Main\Diag\ExceptionHandlerLog::UNCAUGHT_EXCEPTION); // логируем
        LocalRedirect('/500.php');
        exit;
    });
}

Thus, when an internal PHP error occurs if debug is disabled, then a redirect to the /500.php page occurs. And I didn't have to extend the class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question