index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. 'use strict';
  2. var WHITELIST = [
  3. 'ETIMEDOUT',
  4. 'ECONNRESET',
  5. 'EADDRINUSE',
  6. 'ESOCKETTIMEDOUT',
  7. 'ECONNREFUSED',
  8. 'EPIPE'
  9. ];
  10. var BLACKLIST = [
  11. 'ENOTFOUND',
  12. 'ENETUNREACH',
  13. // SSL errors from https://github.com/nodejs/node/blob/ed3d8b13ee9a705d89f9e0397d9e96519e7e47ac/src/node_crypto.cc#L1950
  14. 'UNABLE_TO_GET_ISSUER_CERT',
  15. 'UNABLE_TO_GET_CRL',
  16. 'UNABLE_TO_DECRYPT_CERT_SIGNATURE',
  17. 'UNABLE_TO_DECRYPT_CRL_SIGNATURE',
  18. 'UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY',
  19. 'CERT_SIGNATURE_FAILURE',
  20. 'CRL_SIGNATURE_FAILURE',
  21. 'CERT_NOT_YET_VALID',
  22. 'CERT_HAS_EXPIRED',
  23. 'CRL_NOT_YET_VALID',
  24. 'CRL_HAS_EXPIRED',
  25. 'ERROR_IN_CERT_NOT_BEFORE_FIELD',
  26. 'ERROR_IN_CERT_NOT_AFTER_FIELD',
  27. 'ERROR_IN_CRL_LAST_UPDATE_FIELD',
  28. 'ERROR_IN_CRL_NEXT_UPDATE_FIELD',
  29. 'OUT_OF_MEM',
  30. 'DEPTH_ZERO_SELF_SIGNED_CERT',
  31. 'SELF_SIGNED_CERT_IN_CHAIN',
  32. 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY',
  33. 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
  34. 'CERT_CHAIN_TOO_LONG',
  35. 'CERT_REVOKED',
  36. 'INVALID_CA',
  37. 'PATH_LENGTH_EXCEEDED',
  38. 'INVALID_PURPOSE',
  39. 'CERT_UNTRUSTED',
  40. 'CERT_REJECTED'
  41. ];
  42. module.exports = function (err) {
  43. if (!err || !err.code) {
  44. return true;
  45. }
  46. if (WHITELIST.indexOf(err.code) !== -1) {
  47. return true;
  48. }
  49. if (BLACKLIST.indexOf(err.code) !== -1) {
  50. return false;
  51. }
  52. return true;
  53. };