How to determine if request will result in a successful HTTP request? Two part question here.

What is the proper way in a module to determine if a page request is resulting in a HTTP 200 OK?  Looking through static $stored_headers for a 30x/40x/50x seems wrong.

What is the earliest hook that you can reliably do this from?
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().