javascript - 如何在 AJAX 调用中捕获 sec_error_unknown_issuer 错误?

标签 javascript firefox firefox-addon xul

如何在 AJAX 调用中捕获 sec_error_unknown_issuer 错误?这是一个扩展程序,因此以 Chrome 权限运行。

错误控制台显示:

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)

我想显示一条友好的消息,而不是让应用程序默默地失败。

最佳答案

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

关于javascript - 如何在 AJAX 调用中捕获 sec_error_unknown_issuer 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18729626/

相关文章:

javascript - 如何使用 JSON 和 PHP 将我的对象添加到表单提交的数组中?

http - 记录流量的firefox插件

javascript - 如何在 Firefox Developer Edition 中测试我的插件?

css - 垂直居中在 Firefox 中不起作用

c++ - Firefox 扩展/插件二进制组件向后兼容性

javascript - 如何访问 vuetify.js 2 中 v-data-table 之外的总项目?

javascript - 在 jQuery 中的动态对象上使用 .each?

javascript - 检查元素中的类

Firefox 和 Content-Disposition header

c# - 从 Firefox 扩展到 C# 应用程序的通信