{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/3059","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/3059/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/3059/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/3059/events","html_url":"https://github.com/Automattic/mongoose/issues/3059","id":86869416,"number":3059,"title":"Error codes for Mongoose validation?","user":{"login":"manikandants","id":2004862,"avatar_url":"https://avatars.githubusercontent.com/u/2004862?v=3","gravatar_id":"","url":"https://api.github.com/users/manikandants","html_url":"https://github.com/manikandants","followers_url":"https://api.github.com/users/manikandants/followers","following_url":"https://api.github.com/users/manikandants/following{/other_user}","gists_url":"https://api.github.com/users/manikandants/gists{/gist_id}","starred_url":"https://api.github.com/users/manikandants/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manikandants/subscriptions","organizations_url":"https://api.github.com/users/manikandants/orgs","repos_url":"https://api.github.com/users/manikandants/repos","events_url":"https://api.github.com/users/manikandants/events{/privacy}","received_events_url":"https://api.github.com/users/manikandants/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-10T07:15:58Z","updated_at":"2015-06-11T11:49:40Z","closed_at":"2015-06-10T14:06:49Z","body":"For unique field validation we get error message as follows\r\n\r\n<code>{ [MongoError: insertDocument :: caused by :: 11000 E11000 duplicate key error index: test.users.$phone_1  dup key: { : 9876543210.0 }]\r\n  name: 'MongoError',\r\n  message: 'insertDocument :: caused by :: 11000 E11000 duplicate key error index: test.users.$phone_1  dup key: { : 9876543210.0 }',\r\n  index: 0,\r\n  **code: 11000,**\r\n  errmsg: 'insertDocument :: caused by :: 11000 E11000 duplicate key error index: test.users.$phone_1  dup key: { : 9876543210.0 }' }</code>\r\n\r\nFor required field validation the error is as follows.\r\n\r\n<code>{ [ValidationError: User validation failed]\r\n  message: 'User validation failed',\r\n  name: 'ValidationError',\r\n  errors: \r\n   { email: \r\n      { [ValidatorError: Path `email` is required.]\r\n        properties: [Object],\r\n        message: 'Path `email` is required.',\r\n        name: 'ValidatorError',\r\n        kind: 'required',\r\n        path: 'email',\r\n        value: undefined } } }</code>\r\n\r\nThe interesting part in first error is the error.code as 11000 which can be directly compared to identify the error.\r\nWouldn't it be nice to have either predefined or customized error code for each of these error kind?\r\nfor example 91000 for 'required', 91001 for 'length' etc"},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/111102204","html_url":"https://github.com/Automattic/mongoose/issues/3059#issuecomment-111102204","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/3059","id":111102204,"user":{"login":"manikandants","id":2004862,"avatar_url":"https://avatars.githubusercontent.com/u/2004862?v=3","gravatar_id":"","url":"https://api.github.com/users/manikandants","html_url":"https://github.com/manikandants","followers_url":"https://api.github.com/users/manikandants/followers","following_url":"https://api.github.com/users/manikandants/following{/other_user}","gists_url":"https://api.github.com/users/manikandants/gists{/gist_id}","starred_url":"https://api.github.com/users/manikandants/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manikandants/subscriptions","organizations_url":"https://api.github.com/users/manikandants/orgs","repos_url":"https://api.github.com/users/manikandants/repos","events_url":"https://api.github.com/users/manikandants/events{/privacy}","received_events_url":"https://api.github.com/users/manikandants/received_events","type":"User","site_admin":false},"created_at":"2015-06-11T11:49:40Z","updated_at":"2015-06-11T11:49:40Z","body":"Thanks @vkarpov15 :) That answers my question. I was looking for a common error kind/code for all errors. Using @MattouFP plugin will give errors with 'kind' and solve my issue."}}