How to display a specific error message from a Validation Error. I already display the error with this line of code return res.render("register", {error: err.message});
and show this error ValidationError: User validation failed: email: Email already exists
But it is showing my column field name 'email' and I don't wanna do that. Below is the whole error and I only want to display this message: 'Email already exists'
Ignore the location D: i removed my file directory
ValidationError: User validation failed: email: Email already exists
at ValidationError.inspect
errors:
{ email:
{ ValidatorError: Email already exists
at new ValidatorError (D:)
at validate (D:)
at D:
at process._tickCallback (internal/process/next_tick.js:68:7)
message: 'Email already exists',
name: 'ValidatorError',
properties: [Object],
kind: 'user defined',
path: 'email',
value: '[email protected]',
reason: undefined,
[Symbol(mongoose:validatorError)]: true } },
_message: 'User validation failed',
name: 'ValidationError' }