1

How can I catch a sec_error_unknown_issuer error in an AJAX call? This is in an extension and thus run with Chrome privileges.

The Error Console shows:

mysite.com:443 uses an invalid security certificate.

The certificate is not trusted because no issuer chain was provided.
The certificate expired on 04/30/2012 12:24 AM. The current time is 09/10/2013 06:08 PM.

(Error code: sec_error_unknown_issuer)

I would like to display a friendly message rather than having the application fail silently.

4

1 回答 1

2

this.channel.status似乎有所有的错误代码。问题是,状态是一个数字,它们似乎没有记录在案。Components.results包含这些代码中的一些,但不是全部,并为它们分配一个常数。由于我找不到任何文档,我想我们必须根据常数来猜测出了什么问题。SSL 错误不存在Components.results,是通过反复试验发现的。

这是一个获取一些错误并产生消息的函数。

// Call this from your AJAX error handler
self.GetAJAXFailureCode(this.channel.status);


self.GetAJAXFailureCode = function(Status){
   var ERROR_CODE,ERROR_MESSAGE;

   // Some, but not all can be found in Components.results.
   // All the other codes appear to be undocumented, and have
   // to be discovered through trial and error (thanks Mozilla.)
   switch(Status){
      case(2153390067): 
         ERROR_CODE = 'sec_error_unknown_issuer';
         ERROR_MESSAGE = 'The certificate was signed by an unknown Certificate Authority (add the CA to FF to fix).';
      break;
      case(2153390069):
         ERROR_CODE = 'sec_error_expired_certificate';
         ERROR_MESSAGE = 'The SSL certificate has expired.';
      break;
      case(2152398879):
         ERROR_CODE = 'NS_ERROR_REDIRECT_LOOP';
         ERROR_MESSAGE = 'You seem to be going in circles!';
      break;    
      case( 2152398864):
         ERROR_CODE = 'NS_ERROR_OFFLINE';
         ERROR_MESSAGE = 'There is no network. There is only XUL.';
      break;
      case( 2152398862):
         ERROR_CODE = 'NS_ERROR_NET_TIMEOUT';
         ERROR_MESSAGE = 'The network connection timed out.';
      break;
      case(2152398878): // This happens when the network cable is unplugged.
         ERROR_CODE = 'NS_ERROR_UNKNOWN_HOST';
         ERROR_MESSAGE = 'Please make sure your network cable is securely fastened, and the network is up. (Unknown Host)';
      break;
      default:
         ERROR_CODE = 'unknown_error';
         ERROR_MESSAGE = 'An error with code '+this.channel.status+' occurred. Good luck wih that.';            
   }
   return [ERROR_CODE,ERROR_MESSAGE];      
}
于 2013-09-11T01:43:14.183 回答