eachAsyncMultiError.js 860 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*!
  2. * Module dependencies.
  3. */
  4. 'use strict';
  5. const MongooseError = require('./');
  6. /**
  7. * If `eachAsync()` is called with `continueOnError: true`, there can be
  8. * multiple errors. This error class contains an `errors` property, which
  9. * contains an array of all errors that occurred in `eachAsync()`.
  10. *
  11. * @api private
  12. */
  13. class EachAsyncMultiError extends MongooseError {
  14. /**
  15. * @param {String} connectionString
  16. */
  17. constructor(errors) {
  18. let preview = errors.map(e => e.message).join(', ');
  19. if (preview.length > 50) {
  20. preview = preview.slice(0, 50) + '...';
  21. }
  22. super(`eachAsync() finished with ${errors.length} errors: ${preview}`);
  23. this.errors = errors;
  24. }
  25. }
  26. Object.defineProperty(EachAsyncMultiError.prototype, 'name', {
  27. value: 'EachAsyncMultiError'
  28. });
  29. /*!
  30. * exports
  31. */
  32. module.exports = EachAsyncMultiError;