提交 3cdee8dcc28b6373a80a4e0c16c3f2c34edfca6c

作者 Nick Baugh
1 个父辈 4752870f

added error handler per discussion with @vkarpov15

正在显示 1 个修改的文件 包含 7 行增加2 行删除
... ... @@ -15,8 +15,13 @@ exports = module.exports = function(logger, settings) {
15 15 err.message = 'An unknown error has occured, please try again'
16 16
17 17 if (_.isObject(err) && _.isNumber(err.code) && err.code === 11000) {
18   - err.message = 'Duplicate document already exists in database, try making a more unique value'
19   - err.param = ''
  18 + // <https://github.com/LearnBoost/mongoose/issues/2129>
  19 + var field = err.message.split('index: test.')[1].split('.$')[1]
  20 + // now we have `email_1 dup key`
  21 + field = field.split(' dup key')[0]
  22 + field = field.substring(0, field.lastIndexOf('_'))
  23 + err.message = util.format('Duplicate %s already exists in database, try making a more unique value', field)
  24 + err.param = field
20 25 }
21 26
22 27 // if we pass an error object, then we want to simply return the message...
... ...
注册登录 后发表评论