UNPKG

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