system: revert again and do as much as we can for now #5879

Redirect all UI errors to crash reporter, but set display_errors
to on in PHP production mode to avoid blank 500 static PHP pages.
This commit is contained in:
Franco Fichtner 2022-07-18 15:24:33 +02:00
parent 882630a65a
commit dd4e124655
5 changed files with 11 additions and 21 deletions

View File

@ -434,12 +434,6 @@ EOD;
$lighty_config .= "}\n";
}
if (empty($config['system']['deployment']) || $config['system']['deployment'] == 'development') {
$lighty_config .= "# send static error pages for some errors in non-debug mode\n";
$lighty_config .= "server.error-intercept = \"enable\"\n";
$lighty_config .= "server.errorfile-prefix = \"/usr/local/opnsense/data/webgui/status-\"\n";
}
$lighty_config .= <<<EOD
## error-handler for status 404

View File

@ -208,7 +208,7 @@ zlib.output_compression_level = 1
include_path = "/usr/local/etc/inc:/usr/local/www:/usr/local/opnsense/mvc:/usr/local/opnsense/contrib:/usr/local/share/pear:/usr/local/share"
ignore_repeated_errors = on
error_reporting = E_ALL ^ (E_WARNING | E_NOTICE | E_DEPRECATED | E_STRICT | E_CORE_WARNING | E_COMPILE_WARNING)
display_errors=off
display_errors=on
display_startup_errors=off
log_errors=on
error_log=/tmp/PHP_errors.log

View File

@ -25,7 +25,7 @@ error_reporting = E_ALL ^ (E_WARNING | E_NOTICE | E_DEPRECATED | E_STRICT | E_CO
{% else %}
error_reporting = E_ALL
{% endif %}
display_errors={% if system.deployment|default("") == "debug" %}on{%else%}off{%endif%}
display_errors={% if system.deployment|default("") != "development" %}on{%else%}off{%endif%}
display_startup_errors={% if system.deployment|default("") == "debug" %}on{%else%}off{%endif%}

View File

@ -25,18 +25,22 @@ try {
echo $application->handle($_SERVER['REQUEST_URI'])->getContent();
} catch (\Error | \Exception $e) {
error_log($e);
$response = [
'errorMessage' => $e->getMessage(),
'errorTrace' => $e->getTraceAsString(),
];
if (method_exists($e, 'getTitle')) {
$response['errorTitle'] = $e->getTitle();
} else {
$response['errorTitle'] = gettext('An API exception occurred');
$response['errorMessage'] = $e->getFile() . ':' . $e->getLine() . ': ' . $response['errorMessage'];
error_log($e);
}
header('HTTP', true, 500);
header("Content-Type: application/json;charset=utf-8");
echo json_encode($response, JSON_UNESCAPED_SLASHES);
}

View File

@ -70,16 +70,8 @@ try {
$application = new \Phalcon\Mvc\Application($di);
echo $application->handle($_SERVER['REQUEST_URI'])->getContent();
} catch (\Exception $e) {
if (
isset($application) || (
stripos($e->getMessage(), ' handler class cannot be loaded') !== false ||
stripos($e->getMessage(), ' was not found on handler ') !== false
)
) {
// Render default UI page when controller or action wasn't found
echo $application->handle('/ui/')->getContent();
} else {
echo $e->getMessage();
}
} catch (\Error | \Exception $e) {
error_log($e);
header('Location: /crash_reporter.php', true, 303);
}