error.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. const MongoNetworkError = require('./core').MongoNetworkError;
  3. // From spec@https://github.com/mongodb/specifications/blob/f93d78191f3db2898a59013a7ed5650352ef6da8/source/change-streams/change-streams.rst#resumable-error
  4. const GET_MORE_RESUMABLE_CODES = new Set([
  5. 6, // HostUnreachable
  6. 7, // HostNotFound
  7. 89, // NetworkTimeout
  8. 91, // ShutdownInProgress
  9. 189, // PrimarySteppedDown
  10. 262, // ExceededTimeLimit
  11. 9001, // SocketException
  12. 10107, // NotMaster
  13. 11600, // InterruptedAtShutdown
  14. 11602, // InterruptedDueToReplStateChange
  15. 13435, // NotMasterNoSlaveOk
  16. 13436, // NotMasterOrSecondary
  17. 63, // StaleShardVersion
  18. 150, // StaleEpoch
  19. 13388, // StaleConfig
  20. 234, // RetryChangeStream
  21. 133, // FailedToSatisfyReadPreference
  22. 43 // CursorNotFound
  23. ]);
  24. function isResumableError(error, wireVersion) {
  25. if (error instanceof MongoNetworkError) {
  26. return true;
  27. }
  28. if (wireVersion >= 9) {
  29. // DRIVERS-1308: For 4.4 drivers running against 4.4 servers, drivers will add a special case to treat the CursorNotFound error code as resumable
  30. if (error.code === 43) {
  31. return true;
  32. }
  33. return error.hasErrorLabel('ResumableChangeStreamError');
  34. }
  35. return GET_MORE_RESUMABLE_CODES.has(error.code);
  36. }
  37. module.exports = { GET_MORE_RESUMABLE_CODES, isResumableError };