aggregate-error.js 751 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. const BaseError = require('./base-error');
  3. /**
  4. * A wrapper for multiple Errors
  5. *
  6. * @param {Error[]} [errors] Array of errors
  7. *
  8. * @property errors {Error[]}
  9. */
  10. class AggregateError extends BaseError {
  11. constructor(errors) {
  12. super();
  13. this.errors = errors;
  14. this.name = 'AggregateError';
  15. }
  16. toString() {
  17. const message = `AggregateError of:\n${
  18. this.errors.map(error =>
  19. error === this
  20. ? '[Circular AggregateError]'
  21. : error instanceof AggregateError
  22. ? String(error).replace(/\n$/, '').replace(/^/mg, ' ')
  23. : String(error).replace(/^/mg, ' ').substring(2)
  24. ).join('\n')
  25. }\n`;
  26. return message;
  27. }
  28. }
  29. module.exports = AggregateError;