Created
May 18, 2023 17:37
-
-
Save broskees/d4af10be6283dd04eef3d892a6b6c0b9 to your computer and use it in GitHub Desktop.
Server side error detection WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Some plugins set 5xx status when code runs through expected flows. | |
* This is to track this since it does not trigger any PHP error logs, | |
* so that you have some idea why a site fails with 5xx. | |
*/ | |
add_action ('status_header', function ($status_header, $code, $description, $protocol) { | |
if ( $code >= 500 ) { | |
$backtrace = Logger::debugBacktrace(); | |
$this->logger->error( "Server-side error detected: $status_header. Backtrace: $backtrace" ); | |
} | |
return $status_header; | |
}, 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment