When I was developing the code for Nodewords, I used the following code, to verify if Drupal was serving an error page:
$headers = drupal_get_headers();
if (preg_match('@HTTP/1\.[01]\x20+403@', $headers)) {
return array('type' => NODEWORDS_TYPE_ERRORPAGE, 'id' => 403);
}
if (preg_match('@HTTP/1\.[01]\x20+404@', $headers)) {
return array('type' => NODEWORDS_TYPE_ERRORPAGE, 'id' => 404);
}
The function containing that code is called from nodewords_preprocess_page()
, the implementation of hook_preprocess_page()
.