Need to alter response headers for error pages We have Cloudflare sitting in front of our Drupal sites - and in order to take advantage of their "AlwaysOnline" feature - we need to alter the response code sent in the event of an error.

I want to cater for when the database is unavailable - as this can sometimes happen when upgrading the MySQL server.

The only way I've found so far is to hack the errors.inc file:

if ($fatal) {
    drupal_add_http_header('Status', '504 Service unavailable (with message)');
  }


Is there a more elegant way to achieve what I'm after?
You could use a template_preprocess_maintenance_page() invocation in your theme's template.php so that when you go to maintenance mode (or the DB is down) it will trigger your needed status code:

function MYTHEME_preprocess_maintenance_page(&amp;$variables) {
  drupal_add_http_header('Status', '504 Service unavailable (with message)');
}