2013-09-10 36 views
1

我如何能趕上在AJAX調用sec_error_unknown_issuer錯誤?這是擴展名,因此可以使用Chrome權限運行。如何在AJAX調用中捕獲sec_error_unknown_issuer錯誤?

錯誤控制檯顯示:

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) 

我想顯示一個友好的消息,而不是應用程序失敗靜默。

回答

1

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];  
}