Skip to content

Instantly share code, notes, and snippets.

@broskees
Created May 18, 2023 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save broskees/d4af10be6283dd04eef3d892a6b6c0b9 to your computer and use it in GitHub Desktop.
Save broskees/d4af10be6283dd04eef3d892a6b6c0b9 to your computer and use it in GitHub Desktop.
Server side error detection WordPress
<?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