unique-constraint-error.js 750 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. const ValidationError = require('./../validation-error');
  3. /**
  4. * Thrown when a unique constraint is violated in the database
  5. */
  6. class UniqueConstraintError extends ValidationError {
  7. constructor(options) {
  8. options = options || {};
  9. options.parent = options.parent || { sql: '' };
  10. options.message = options.message || options.parent.message || 'Validation Error';
  11. options.errors = options.errors || {};
  12. super(options.message, options.errors);
  13. this.name = 'SequelizeUniqueConstraintError';
  14. this.errors = options.errors;
  15. this.fields = options.fields;
  16. this.parent = options.parent;
  17. this.original = options.parent;
  18. this.sql = options.parent.sql;
  19. }
  20. }
  21. module.exports = UniqueConstraintError;