Improve error handling in page_renderer.php
This commit is contained in:
@@ -4,9 +4,10 @@ class SPLPageRenderer {
|
||||
public function renderCouncilPage($config, $candidates) {
|
||||
ob_start();
|
||||
|
||||
set_error_handler(function($errno, $errstr, $errfile, $errline) {
|
||||
// Clear any output if an error occurred
|
||||
ob_clean();
|
||||
$didError = false;
|
||||
|
||||
set_error_handler(function($errno, $errstr, $errfile, $errline) use(&$didError) {
|
||||
$didError = true;
|
||||
error_log("Error: $errstr in $errfile on line $errline");
|
||||
return true; // Prevent default error handling
|
||||
});
|
||||
@@ -17,8 +18,8 @@ class SPLPageRenderer {
|
||||
|
||||
$content = ob_get_clean();
|
||||
|
||||
// Explictly return null if we didn't generate any content
|
||||
if (!empty($content)) {
|
||||
// Explictly return null if we didn't generate any content or if there was an error
|
||||
if (!empty($content) && !$didError) {
|
||||
return $content;
|
||||
} else {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user