messages.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * The default built-in validator error messages. These may be customized.
  3. *
  4. * // customize within each schema or globally like so
  5. * const mongoose = require('mongoose');
  6. * mongoose.Error.messages.String.enum = "Your custom message for {PATH}.";
  7. *
  8. * As you might have noticed, error messages support basic templating
  9. *
  10. * - `{PATH}` is replaced with the invalid document path
  11. * - `{VALUE}` is replaced with the invalid value
  12. * - `{TYPE}` is replaced with the validator type such as "regexp", "min", or "user defined"
  13. * - `{MIN}` is replaced with the declared min value for the Number.min validator
  14. * - `{MAX}` is replaced with the declared max value for the Number.max validator
  15. *
  16. * Click the "show code" link below to see all defaults.
  17. *
  18. * @static messages
  19. * @receiver MongooseError
  20. * @api public
  21. */
  22. 'use strict';
  23. const msg = module.exports = exports = {};
  24. msg.DocumentNotFoundError = null;
  25. msg.general = {};
  26. msg.general.default = 'Validator failed for path `{PATH}` with value `{VALUE}`';
  27. msg.general.required = 'Path `{PATH}` is required.';
  28. msg.Number = {};
  29. msg.Number.min = 'Path `{PATH}` ({VALUE}) is less than minimum allowed value ({MIN}).';
  30. msg.Number.max = 'Path `{PATH}` ({VALUE}) is more than maximum allowed value ({MAX}).';
  31. msg.Number.enum = '`{VALUE}` is not a valid enum value for path `{PATH}`.';
  32. msg.Date = {};
  33. msg.Date.min = 'Path `{PATH}` ({VALUE}) is before minimum allowed value ({MIN}).';
  34. msg.Date.max = 'Path `{PATH}` ({VALUE}) is after maximum allowed value ({MAX}).';
  35. msg.String = {};
  36. msg.String.enum = '`{VALUE}` is not a valid enum value for path `{PATH}`.';
  37. msg.String.match = 'Path `{PATH}` is invalid ({VALUE}).';
  38. msg.String.minlength = 'Path `{PATH}` (`{VALUE}`) is shorter than the minimum allowed length ({MINLENGTH}).';
  39. msg.String.maxlength = 'Path `{PATH}` (`{VALUE}`) is longer than the maximum allowed length ({MAXLENGTH}).';