How to determine if request will result in a successful HTTP request?
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' =&gt; NODEWORDS_TYPE_ERRORPAGE, 'id' =&gt; 403);
  }

  if (preg_match('@HTTP/1\.[01]\x20+404@', $headers)) {
    return array('type' =&gt; NODEWORDS_TYPE_ERRORPAGE, 'id' =&gt; 404);
  }


The function containing that code is called from nodewords_preprocess_page(), the implementation of hook_preprocess_page().