Custom Error Messages with Mongoose

前端 未结 8 502
旧巷少年郎
旧巷少年郎 2021-02-01 04:06

So according to the mongoose docs, you are supposed to be able to set a custom error message in the schema like so:

 var breakfastSchema = new Schema({
  eggs: {         


        
8条回答
  •  梦谈多话
    2021-02-01 04:50

    verificationToken.save( function (err) {
        if (err) {
          return res.status(400).send({
              message: (err.name === 'MongoError' && err.code === 11000) ? 'Email already exists !' : errorHandler.getErrorMessage(err)
          });
        }
        else {
          return console.log('No Error');
        }
      });
    

提交回复
热议问题